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

Re^2: printing certain number of data

by drock (Beadle)
on Jul 01, 2004 at 16:49 UTC ( [id://371167]=note: print w/replies, xml ) Need Help??


in reply to Re: printing certain number of data
in thread printing certain number of data

I would rather use substr since these are techinically strings! Can substr allow for spaces in between the indexs? FILEOUT looks like E2323 E2343 E4344
while (<FILE>) { chomp $_; print FILEOUT substr($_, 0, 7);
but where do I go from here to get the remaining E string list? I have not been able to make substr include spaces as my output is all strung together as such.... E2323E3243E2432E543

Replies are listed 'Best First'.
Re^3: printing certain number of data
by Fletch (Bishop) on Jul 01, 2004 at 18:27 UTC

    substr won't include any spaces if your original source string doesn't have any. At any rate, just make an array out of your source string and use what I showed above.

    my @src; { my $tmp = $a; push @src, substr( $tmp, 0, 7, "" ) while $tmp; } # . . . as above . . .

    Update: And looking again at your sample it appears you might have rows of space separated data, in which case you'd want to use something along the lines of while( <SRC> ) { chomp; push @src, split( /\s+/, $_)  } to build @src. Sample data in <code> tags would help clear things up.

Re^3: printing certain number of data
by Not_a_Number (Prior) on Jul 01, 2004 at 17:28 UTC

    I'm afraid I have no idea of what you are trying to achieve. In your original post you say:

    ...how to print 8 scalers/elements then \n, then 5 more lines of 8 or less for a max total of 40...

    but that makes a maximum total of 48.

    And maybe you could show us what your input file looks like?

    dave

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-29 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found