> -----Original Message-----
> From: Tony Esposito [mailto:tony1234567...@yahoo.co.uk] 
> Sent: Tuesday, June 02, 2009 15:29
> To: Beginners Perl
> Subject: split() does not work with all characters
> 
> When trying to use split() where the delimiter is passed from 
> the command-line ( as seen in stub code that follows ), 
> the code fails to parse/split input file via some characters 
> (e.g. | ) but it runs ok for others (e.g. , ).
> 
        The | has special significance when used in regex, so if you are just 
after whatever characters are inputted, then you will need to set the regex so 
it won't interpret as a regex value, so you could do:

        @cfgData = split(/\Q$opt{d}\E/);
        where \Q Backslash all  following nonalphanumeric characters and
                \E ends the \Q
 
Wags ;)
David R. Wagner
Senior Programmer Analyst
FedEx Freight
1.719.484.2097 TEL
1.719.484.2419 FAX
1.408.623.5963 Cell
http://fedex.com/us 


> Any idea what could be causing this?
> 
> 
> Code:
> --------
> 
>   use vars qw/ %opt /;        
>   use Getopt::Std;
>   my $optString = 'd:';
> 
>   getopts( "$optString", \%opt );
> 
>   while(<FILE>) {
>     @cfgData = split(/$opt{d}/); 
>     ...
>   }
> 
> 
> 
>       
> 

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to