Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

store perl -c result into a array 1

Status
Not open for further replies.

NEVERSLEEP

Programmer
Apr 14, 2002
667
CA
lets say u do
$value = system($command);
it will return a 0 or 1 depending if it succed
so i was wondering how to store
@value = ?????('perl -c $file');
# so that $value[0] contain the 1st error and so on...

thanks again (...i keep saying that to u guys [lol]) ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Use backticks, like this:

my @output_lines = `perl -c $file`;

each line of output from the command you are executing will
be stored as an element of the array. I'm not sure if
standard error gets included by default - it may be that
only standard output gets included. You might have to do
something more to get standard error included as well.

I found some information in the perldocs about capturing
STDERR from an external command - do this:

perldoc -q STDERR

the 1st topic that comes up is

How can I capture STDERR from an external command?

so hopefully that will give you some ideas.

HTH. Hardy Merrill
 
thanks for the tip ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
heem i dont seem to get this right...
Code:
my $var = "drive:\\path\\to\\valid\\script.pl";
my @storer = 'perl -c $file';
my $counter = 1;
foreach (@storer) {
 print "\n$counter : $_";
 $counter++;
}

will output
1 : perl -c $file

and if we change the ' to "
the output is now
1 : perl -c drive:\\path\\to\\valid\\script.pl

since when that quots and double quotes make a difference [3eyes]?
---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
yep :) variables in single quotes are just left as text, variables in double quotes are interpreted and their values inserted into the string Mike
______________________________________________________________________
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
ok then...
hey mike im aving a hard time on this
can u help me store that result ? ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
On a Us keyboard the key to the left of 1 (not the number pad) is the back tick... thats the key you want to use to run a system command an capture the output.

$someval = `hostname`;
 
Neversleep -- copy and paste Yauncin's code above, that will give you the correct code. Mike
______________________________________________________________________
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
[bugeyed] [bomb]
[flush2]
[hammer]
???? what ??

'... thats the key '
you mean this ~ ?

'you want to use to run a system command an capture the output.'
that exactly ! how to ?

$someval = `hostname`;

'copy and paste Yauncin's code above, that will give you the correct code'

?
am i being stupid or what ? [lol]
please explain me with code
thanks ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
~ is created while holding shift, ` is created when not, ` is a backtick. ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
[2thumbsup] ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
You ok with that Neversleep? Mike
______________________________________________________________________
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
very !
thanks a lot
i just didnt know what backtick did in perl
thank all ---------------------------------------
wmail.jpg


someone knowledge ends where
someone else knowledge starts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top