Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Finding a pattern to split on

by kilinrax (Deacon)
on Dec 05, 2000 at 01:00 UTC ( [id://44852]=note: print w/replies, xml ) Need Help??


in reply to Finding a pattern to split on

You don't want to split the file using s/\n/ms, that's a substitution operator. Use /\n/, a match operator.

Replies are listed 'Best First'.
Re: Re: Finding a pattern to split on
by urburp (Initiate) on Dec 05, 2000 at 01:26 UTC

    Sorry, meant:

    split /\n/sm

    Ideas??

      The following code should work fine, assuming $data contains what you're trying to split:
      #!/usr/bin/perl -w use strict; my $data = q|Title Line Author Line URL Line |; my @data = split /\s*\n\s*/, $data; my $i; for ($i=0; $i<=$#data; $i++){ print "$i: $data[$i]\n"; }
      However, if you're reading from a file, i suspect you want something more like this:
      #!/usr/bin/perl -w use strict; open DATA, 'splitdata.txt'; my @data; while (<DATA>) { chomp; s|^\s+||; s|\s+$||; push @data, $_; } my $i; for ($i=0; $i<=$#data; $i++){ print "$i: $data[$i]\n"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-26 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found