Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Can anyone pls tell me how to cleanup this in Perl.

by Athanasius (Monsignor)
on Mar 19, 2013 at 04:26 UTC ( #1024199=note: print w/ replies, xml ) Need Help??


in reply to Can anyone pls tel me how to cleanup this in Perl.

NetWallah’s advice is correct, and if you follow it you will save yourself a lot of time and difficulty in the long run. But — to show off Perl’s text-munging power — the following quick-and-dirty script (OK, hack) will produce output close to what you’re seeking (for this data):

#! perl use strict; use warnings; if (my ($field) = grep { /^!!./ } split /\|/, do { local $/; <DATA> }) { my @lines = $field =~ m{ minor-latin%22%3E (.*?) %3C }gx; for (@lines) { s{ \\x92 }{'}gx; s{ %5C } {}gx; s{ %27 }{'}gx; s{ %26amp; }{&}gx; } print join("\n", @lines); } __DATA__ <insert the data here>

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


Comment on Re: Can anyone pls tell me how to cleanup this in Perl.
Download Code
Re^2: Can anyone pls tell me how to cleanup this in Perl.
by Anonymous Monk on Mar 19, 2013 at 06:07 UTC

    Thanks Athanasius. That was cool. I am not that good with perl. my question may be foolish but pls can you tell me, how the script should be modified if the data is already in a string. means if '$data' contains the whole data and kindly tell me how I should modify this script.

      If the data has already been read into the variable $data as a single string, then just replace the line:

      if (my ($field) = grep { /^!!./ } split /\|/, do { local $/; <DATA> })

      with:

      if (my ($field) = grep { /^!!./ } split /\|/, $data)

      (The expression do { local $/; <DATA> } slurps the whole of the data in from the __DATA__ block at the foot of the script.)

      Hope that helps,

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

        Wow, Cool. That works. Thanks a lot Mr. Athanasius :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1024199]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-08-29 02:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls