Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Splitting a Text File

by hdb (Prior)
on Jul 26, 2013 at 16:45 UTC ( #1046559=note: print w/replies, xml ) Need Help??


in reply to Splitting a Text File

If you use parentheses in the separator given to split, the captured string will also be part of the resulting array. See this example:

use strict; use warnings; use Data::Dumper; my $file = "start<<<<part2>>>>middle<<<<part3>>>>end"; my @parts = split /<<<<(.+?)>>>>/, $file; print Dumper \@parts;

which results in

$VAR1 = [ 'start', 'part2', 'middle', 'part3', 'end' ];

and gives you the content for your splitted files and the names in alternation.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1046559]
help
Chatterbox?
[choroba]: needed everywhere, available rarely
[LanX]: Question: starting a script from an icon in Windows, but after C-c the window closes ... what I want is to restart in the cmd.exe. Recommendations?
[Corion]: LanX: What do you mean by "restart in the cmd.exe" ?
[Corion]: Do you want to launch a script and keep the command prompt/console window open?
[Corion]: Do you want to wait for a key press before closing the window?
[LanX]: I want the command line in the history

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (12)
As of 2017-03-27 15:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.