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

Re: Split on whitespace or other criteria

by neniro (Priest)
on Jan 30, 2005 at 20:38 UTC ( [id://426421]=note: print w/replies, xml ) Need Help??


in reply to Split on whitespace or other criteria

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; while(<DATA>) { chomp; s/-/ -/g; print Dumper [split(/\s+/, $_)]; } __DATA__ 123.45 345.3 234.67 34.56 234.1 123.87 897.34 567.32-100.90
How about adding a blank before the '-'sign.

Replies are listed 'Best First'.
Re^2: Split on whitespace or other criteria
by Anonymous Monk on Jan 30, 2005 at 20:42 UTC
    yes, should hav mention that a blank is required before -ve sign thanks
      @array = grep { $_ !~ /^\s*$/ } split '(\d+(?:\.\d*)*)+|\D+', $line;

      So there is no matter what chars you put between digits.
        the -ve sign is lost on the split?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found