with the script shown below I extract the four numbers from the string.
#!/usr/bin/perl
use 5.10.0;
use strict;
use warnings;
#
my $str = "760x35+10+20";
my $re = qr/(d+)[x](d+)[+-](d+)[+-](d+)/;
my @line = split(/$re/, $str);
say scalar(@line), ": ",join("=",@line);
for (@line)
{
say qq/>$_</;
}
my ($u, $w, $h, $x, $y) = split(/$re/, $str);
say qq/u= >$u< w= >$w< h= >$h< x= >$x< y= >$y</;
> my $re = qr/(d+)[x](d+)[+-](d+)[+-](d+)/;
> my @line = split(/$re/, $str);
You are using split the wrong way. The regexp shold only be the *delimiters*.
Here's my two alternative ways to accomplish the task:
# use the match operator with the regexp
my @l2 = $str =~ m/$re/;
say scalar(@l2), ": ",join("=",@l2);
# split the string based on the delimiters
my @l3 = split(/[x+-]/, $str);
say scalar(@l3), ": ",join("=",@l3);
Both will print the string:
4: 760=35=10=20
--
Pelle
"D’ä e å, vett ja”, skrek ja, för ja ble rasen,
”å i åa ä e ö, hörer han lite, d’ä e å, å i åa ä e ö"
- Gustav Fröding, 1895
--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: CAOURYnAw1WrNXe6Gx+ezf6cGk9S_OQhmZq80PoywJ+__c=_Gs w@mail.gmail.com">http://lists.debian.org/CAOURYnAw1WrNXe6Gx+ezf6cGk9S_OQhmZq80PoywJ+__c=_Gs w@mail.gmail.com