Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I tried to write some code to help you out, but I'm not at all sure what you're doing. First, split works on strings, not arrays. It also returns a list. So...

split(/,/,@array1,4);
attempts to split an array, which is never going to happen. Then...
$list=split(/,/,@array1,4);
attempts to assign the list that you wanted to appear to $list, which is a scalar. In scalar context, split returns the number of elements that resulted from the split, not the elements themselves. And foreach also works on lists, not scalars.

Regarding your data, is it lines of data with embedded newlines? As newlines, wouldn't they be separate lines already? Anyway, maybe this will help:

foreach my $line (<DATA>) { #assuming you have a data source chomp $line; @lines = split /\\n/, $line, 4; foreach $l (@lines) { # <--that's an L, not a one $l =~ s/^,//; @elems = split /,/, $l; print "$_ " for @elems; print "\n"; } } __DATA__ name1,a1,b1,c1,\n,name2,a2,b2,c2\nname3,a3,b3,c3,\n,name4,a4,b4,c4 name5,a5,b5,c5,\n,name6,a6,b6,c6\nname7,a7,b7,c7,\n,name8,a8,b8,c8
This produces:
name1 a1 b1 c1 name2 a2 b2 c2 name3 a3 b3 c3 name4 a4 b4 c4 name5 a5 b5 c5 name6 a6 b6 c6 name7 a7 b7 c7 name8 a8 b8 c8
--marmot

Further reading:

  • perldoc -f split
  • perldoc -f chomp
  • perldoc perldsc

In reply to Re: Nested Loop Problems by furry_marmot
in thread Nested Loop Problems by cuautemoc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found