R
Roman Kaganovich
Hello ,
I wrote a program based an example from "Perl Cookbook".
I run it at file test that contain this text:
blah blah (22.34 215.645)
something (1978 404)
opla 1234
When I use code:
#!/usr/bin/perl -w
my $x=$ARGV[1];
open FILE,$ARGV[0] or die "$!";
while (<FILE>){
chomp;
s/\((\d+)/$x * $1/e;
$x=$ARGV[1];
print "$_\n";
}
I got no errors.
But if I modify a code to:
#!/usr/bin/perl -w
my $x=$ARGV[1];
my $y=$ARGV[2];
open FILE,$ARGV[0] or die "$!";
while (<FILE>){
chomp;
s/\((\d+\.\d+|\d+?)(\s+?)(\d+\.\d+|\d+?)/$x * $1 $y * $3/ex;
$x=$ARGV[1];
$y=$ARGV[2];
print "$_\n";
}
I got next output:
(Missing operator before $y?)
syntax error at ./col.pl line 10, near "$1 $y"
Execution of ./col.pl aborted due to compilation errors.
I wrote a program based an example from "Perl Cookbook".
I run it at file test that contain this text:
blah blah (22.34 215.645)
something (1978 404)
opla 1234
When I use code:
#!/usr/bin/perl -w
my $x=$ARGV[1];
open FILE,$ARGV[0] or die "$!";
while (<FILE>){
chomp;
s/\((\d+)/$x * $1/e;
$x=$ARGV[1];
print "$_\n";
}
I got no errors.
But if I modify a code to:
#!/usr/bin/perl -w
my $x=$ARGV[1];
my $y=$ARGV[2];
open FILE,$ARGV[0] or die "$!";
while (<FILE>){
chomp;
s/\((\d+\.\d+|\d+?)(\s+?)(\d+\.\d+|\d+?)/$x * $1 $y * $3/ex;
$x=$ARGV[1];
$y=$ARGV[2];
print "$_\n";
}
I got next output:
Scalar found where operator expected at ./col.pl line 10, near "$1 $y"./col.pl test 10 2
(Missing operator before $y?)
syntax error at ./col.pl line 10, near "$1 $y"
Execution of ./col.pl aborted due to compilation errors.