Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: parsing question

by joeface (Pilgrim)
on Dec 07, 2006 at 16:20 UTC ( #588381=note: print w/ replies, xml ) Need Help??


in reply to Re^2: parsing question
in thread parsing question

This sets the default line-separator (held in "$/", normally set to "\n") to undef, so that whatever comes in from STDIN (<>) will get slurped up, split on the string "-{103}", and assigned to @sections.

A short example... put the following into a script named "test.pl":

#!/usr/bin/perl -w use strict; my @sections = split 'FOO', do {local $/; <>}; close *ARGV; print join("\n", @sections);

Then, put the following into a file called "test.txt":

FOObarFOObarFOObarFOObarFOObar FOObarFOObarFOObarFOObarFOObar FOObarFOObarFOObarFOObarFOObar

Then, run the following at the command-line:

cat test.txt | ./test.pl


Comment on Re^3: parsing question
Select or Download Code
Replies are listed 'Best First'.
Re^4: parsing question
by smist (Acolyte) on Dec 07, 2006 at 17:42 UTC
    Thanks for the reply. I'm not seeing where "-{103}" is, in the text file I'm parsing.

    UPDATED: Nevermind the above. :-) I'm such a newbie. I didn't recognize the {} as being quantifiers in a regex. So, "-{103}" is simply the line of hyphens used to separate the sections in the text file.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2015-07-29 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (263 votes), past polls