Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: splitting files into multiple sections to be processed as a file

by CountZero (Bishop)
on Nov 29, 2011 at 23:08 UTC ( [id://940723]=note: print w/replies, xml ) Need Help??


in reply to Re^2: splitting files into multiple sections to be processed as a file
in thread splitting files into multiple sections to be processed as a file

You can save the subcontents in an array, that is easy.
use Modern::Perl; use Data::Dump qw/dump/; my @subsections; { local $/ = "\n\n"; @subsections = <DATA> } say dump(@subsections); __DATA__ subsection 1 line 1 subsection 1 line 2 subsection 1 line 3 subsection 1 line 4 subsection 2 line 1 subsection 2 line 2 subsection 2 line 3 subsection 3 line 1 subsection 3 line 2 subsection 3 line 3 subsection 4 line 1 subsection 4 line 2
But what file-specific operations do you want to perform on the subcontents?

Update: You can use a scalar reference as a "virtual" (or in-memory) file (since Perl v5.8.0.)

open my $fh, '<', \$subsections[1]; print while <$fh>;

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-24 08:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found