Steve Bertrand wrote:
> Paul wrote:
>> I am assigned the output of a function to a variable.
>>
>> my$variable = (function);
>> print "$variable\n";
>>
>> The output is:
>> text
>> 0
>>
>> So I try this:
>>
>> chop my$variable = (function);
>> print "$variable\n";
>>
>> The output is:
>> text
>> *** this is blank space output *****
>>
>> So it get's rid of the "0", but outputs a new line.
>>
>> I try double chopping with same results.
>>
>> How can I finally get rid of it, I just want the text output.  Ugh.
>>
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> my $variable = "text\n0";
> 
> print "first: $variable\n";
> 
> $variable =~ s/\s+//;
> $variable =~ s/\d+//;
> 
> print "second: $variable\n";
> 
> --- output ---
> 
> pearl# ./rmtext.pl
> first: text
> 0
> second: text
> pearl#

That may not be so good. My code assumes that 'text' contains no digits.

This may be better:

#!/usr/bin/perl

use warnings;
use strict;

my $variable = "text\n0";

print "first: $variable\n";

$variable = (split (/\s+/, $variable))[0];

print "second: $variable\n";

Steve

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to