Peroli said:
Hi,
Very easy problem:
my $pair = "var=value";
($fake,$value) = split/=/,$pair;
I want get only value, but not var!
How can I do that else,without $fake variable?
Try this...
#!/usr/bin/perl
use warnings;
use strict;
my $pair = "var=value";
$pair =~ s/[^=]+=//;
print $pair;
Yes, that works, but I wouldn't recommend the solution. For one, it
destroys the entry variable $pair, and you end up with the result
in an inappropriately named variable. Quite generally, if you want to
extract text from a string, destroying the unwanted part is only
justified if the unwanted part is much easier to match than the wanted
part. That isn't the case here. So, if you want a regex solution,
catch everything after the first "=":
my ( $value) = $pair =~ /=(.*)/;
With split, the unwanted variable name can be skipped like this:
my ( undef, $value) = split /=/, $pair;
or
my $value = ( split /=/, $pair)[ 1];
I prefer the second. Code untested.
Anno