system does not return the output of the system command.
If you want to collect the standard output (not the standard error), you usually use the backticks operator:
my $dir=qx(pwd);
or, if you prefer, the equivalent
my $dir=`pwd`;
(Of course, for getting the working directory, you could easier do it without shelling out - see the module Cwd).
Note that backticks interpolate...
User Profile
Collapse
-
If you don't know Perl well, it would already help if you sketch the algorithm you want to implement in pseudo-code (or in any other programming language you are used to), and point out which part you are having problems implementing in Perl. We can provide much better help if we know your level of knowledge.Leave a comment:
-
If you sure that *all* your function's closing curlies are in column 1, and no other curly brace is in column 1, and you want to insert something just before the function's closing curly brace, things are trivial. You just read your file line by line, and whenever you encounter the closing of a function, you insert your new statement.
However this solution is so obvious, that I there must be some hidden problem I don't understand yet....Leave a comment:
-
???
What exactly was unclear with my last response from March 21?Leave a comment:
-
This doesn't really answer my question.... Because when the function braces are only in column 1, and the other braces are not in column 1, you can use this to distinguish them, by just searching for braces at the beginning of a line.Leave a comment:
-
But in this particular case, the opening brace and the closing brace for the function body always are in the beginning of the line, aren't they?Leave a comment:
-
The parameter array @_ is an *alias* for the actual parameter list, which means that if you would assign to some element of @_, and the corresponding parameter is an lvalue, this lvalue would be changed.
Except in the rare cases where you want this to happen, good practice is to assign the parameters to local variables, which also has the advantage of having "understandable " names ($self is easier to understand than $_[0])...Leave a comment:
-
From your wording ("batch files"), I assume that you are running on Windows.
What information do you have on the batch files? If they depend on each other (for example, one batch file sets an environment variable, which the next one needs), you need to create a new batchfile containing calls to all of them, and execute them in one go.Leave a comment:
-
How about non-greedy pattern matching? I.e. replace
.*
by
.*?
in your regexp.Leave a comment:
-
You get the file size using -s operator:
my $size_of_file=-s $path_to_file;Leave a comment:
-
So what where the values of $id and $offset right before doing the call to selectall_array ref?
IMO it doesn't make sense discussing the result, as long as you get the error message in selectall_array ref.Leave a comment:
-
I don't question your "idea", but your "$id" (pun intended). No matter how many languages your have, $id will be the SAME value in each iteration.
BTW, you didn't comment yet on my earlier posting, where I asked you: "did you verify that $id and $offset has a reasonable value?"Leave a comment:
-
That's not the point. I would like to know, why you use the SAME name for two DIFFERENT local variables? This really looks like a bug. And why are you assigning @_ *INSIDE* a loop, though it doesn't change? Your code, as posted, is equivalent to the following:
my ($id, $offset) = @_;
for my $this_variable_ is_not_used_any way (1 .. $lang_size ){
my @array = ();
...
}
Are you aware...Leave a comment:
-
Well, since the error is issued by selectall_array ref, did you verify that $id and $offset has a reasonable value? I see that you get them from @_, so it might be that they are already garbage at this point.
Further, this construct is weird:
for my $id(1 .. $lang_size ){
my ($id, $offset) = @_;
...
}
You have a variable $id, and in the loop you "hide" it with another...Leave a comment:
-
I guess you mean "use warnings", and not "use warning"....
This is strange, because I would have expected that you should get warning (for example) for
push(@main, @{$i}[0]);
Which Perl version are you using?Leave a comment:
-
-
rovf replied to How to count no. of occurance with line no. of multiple words individually in a file?in Perl> It was not able to locate "strict.pm" .
This is a standard module since Perl 5. Either you are using Perl 4 (please check with "perl --version"), or your installation is seriously broken (in which case I only can suggest re-installing Perl - I wouldn't trust a Perl installation which not even has strict.pm!).
RonaldLeave a comment:
-
rovf replied to How to count no. of occurance with line no. of multiple words individually in a file?in PerlCould you please be more precise about where your problem is? You don't even post code (except your initial version which you, presumably, have modified in the meantime).Leave a comment:
-
At least in the example which you posted, you don't pass any argument to hello.pl. BTW, you would have found out by yourself if you had used strict and warnings.Leave a comment:
-
96Code:$ perl -lwe 'use strict; my $mystring="1=2,2,4,3,3,3,1,2,4,2,4,2,2,2,4|2=4,3,3, 2,4,2,3,3 ,2,2,3,3,4,5,2|3=1,4,2,4,4,5,4,2,3,4,5,5,2,3,5"; my %mystring=(!!$mystring => length($m ystring)); print $mystring{1}'
To get an even more accurate answer, please post a small, but complete program, showing your problem.Leave a comment:
No activity results to display
Show More
Leave a comment: