It's a common mistake to assume that chomp takes a value, chomps it, and returns the result, but this isn't the case; chomp operates on the expression you feed it. In particular, that expression has to be an lvalue.
You'll have to save your command's output in a variable to chomp it, which I think will also make your code more readable. :) You can chomp and assign in the same step, e.g.:
foreach my $min (20 .. 29) { foreach my $sec (@seconds) { chomp(my $res = `cut -d "|" -f 1,10,13 SMSCDR*$date$hour$minut +e*.log |grep "Submit|SMPP" |grep "$hour:$min:$sec" |sort |uniq -c`); my $SMPP_count = (split /\s+/, $res)[0]; print $SMPP_count; } }
Though for the sake of readability I'd still suggest separating this a bit further and not doing everything in the same step (the command you're invoking is complicated enough, after all). Meanwhile, this:
syntax error at second.pl line 24, near ")["
is because you've got the parentheses in the wrong place. You're doing split(..., ...)[...], trying to treat split as if it were a list, but it isn't. However, if you put what split returns into a list, it works: (split ..., ...)[...]. I've fixed that above.
Finally, you don't need a character class in your regexp you feed to split, though depending on what exactly your command returns, you may want to split on any (positive) amount of whitespace (\s+), not just one whitespace character (\s). I've changed that above as well.
In reply to Re: using system command in regex
by AppleFritter
in thread using system command in regex
by ravi45722
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |