[29417] in Perl-Users-Digest
Perl-Users Digest, Issue: 661 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 19 09:09:40 2007
Date: Thu, 19 Jul 2007 06:09:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 19 Jul 2007 Volume: 11 Number: 661
Today's topics:
A perl issue when execute system call <jeanwelly@gmail.com>
Re: A perl issue when execute system call <wahab@chemie.uni-halle.de>
Re: FAQ 5.6 How do I make a temporary file name? <brian.d.foy@gmail.com>
how to distill this par of string from whole string <jeanwelly@gmail.com>
Re: how to distill this par of string from whole string <wahab@chemie.uni-halle.de>
Re: new lines in the way <wahab@chemie.uni-halle.de>
Re: new lines in the way anno4000@radom.zrz.tu-berlin.de
Re: new lines in the way anno4000@radom.zrz.tu-berlin.de
pid from startet process carlo.maier@netcologne.de
Re: retrieving usenet messages III <bik.mido@tiscalinet.it>
STDOUT and STDERR redirection fails for forked process <mailbox@petervannes.nl>
STDOUT and STDERR redirection fails for forked process <mailbox@petervannes.nl>
Re: STDOUT and STDERR redirection fails for forked proc anno4000@radom.zrz.tu-berlin.de
Re: Using the split function <bik.mido@tiscalinet.it>
Why ($fh, $file) = mkstemps( "tmpfileXXXXXX", $suffix); <laffdez@gmail.com>
Re: Why ($fh, $file) = mkstemps( "tmpfileXXXXXX", $suff anno4000@radom.zrz.tu-berlin.de
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 19 Jul 2007 11:42:17 -0000
From: jeanwelly <jeanwelly@gmail.com>
Subject: A perl issue when execute system call
Message-Id: <1184845337.468324.52940@m37g2000prh.googlegroups.com>
Hi,
I met with a hang issue when using perl in some Unix server, don't
why? Could you help?
print "start...\n";
my $result = `which command`;
print "Stop...\n"; # can not call to here.
chomp($result);
It looks really strange to me. Thanks!
------------------------------
Date: Thu, 19 Jul 2007 13:50:59 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: A perl issue when execute system call
Message-Id: <f7nj74$2bdl$1@nserver.hrz.tu-freiberg.de>
jeanwelly wrote:
> I met with a hang issue when using perl in some
> Unix server, don't why? Could you help?
>
> print "start...\n";
> my $result = `which command`;
> print "Stop...\n"; # can not call to here.
> chomp($result);
What is "command"?
What happens if you put the "command"
into a shell?
$~jeanwelly> command [enter]
Regards
M.
------------------------------
Date: Thu, 19 Jul 2007 06:32:57 -0500
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 5.6 How do I make a temporary file name?
Message-Id: <190720070632571542%brian.d.foy@gmail.com>
In article <5g0nvrF3eahuuU1@mid.dfncis.de>,
<anno4000@radom.zrz.tu-berlin.de> wrote:
> Clenna Lumina <savagebeaste@yahoo.com> wrote in comp.lang.perl.misc:
> > PerlFAQ Server wrote:
> There's another paren missing, and the indentation is messy. Here is a
> corrected version:
I've updated the answer. Thanks,
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Thu, 19 Jul 2007 12:20:44 -0000
From: jeanwelly <jeanwelly@gmail.com>
Subject: how to distill this par of string from whole string
Message-Id: <1184847644.306174.160170@x40g2000prg.googlegroups.com>
$mystring = "andgjdkj..dlodjghghdhhdghhd\ndkkdkd\n/usr/local/ddd\n";
I want to distill "/usr/loca/add" from the string and assign to a
variable, thanks!
------------------------------
Date: Thu, 19 Jul 2007 14:31:56 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: how to distill this par of string from whole string
Message-Id: <f7nljt$2c2e$1@nserver.hrz.tu-freiberg.de>
jeanwelly wrote:
> $mystring = "andgjdkj..dlodjghghdhhdghhd\ndkkdkd\n/usr/local/ddd\n";
>
> I want to distill "/usr/loca/add" from the string and assign to a
> variable, thanks!
if you split the "mystring" on \n, your wanted string
will be at the third place (index = 2):
...
my ($mystring, $distilled);
$mystring = "andgjdkj..dlodjghghdhhdghhd\ndkkdkd\n/usr/local/ddd\n";
$distilled = (split /\n/, $mystring )[2];
...
Regards
M.
------------------------------
Date: Thu, 19 Jul 2007 09:48:29 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: new lines in the way
Message-Id: <f7n50i$27f1$1@nserver.hrz.tu-freiberg.de>
new2perl@gmail.com wrote:
> I am trying to parse a text file that looks like this:
> VAR1=15
> VAR2=16
> VAR=17
>
> FIRSTJOKE=this is my first joke. its isnt that funny but its still
> pretty good bla hbls dfd fsdf dsf sdfsd sd fdssd sdfdsf
> dsfdsfsdsdfsfsd
...
...
> # It only prints out the first line of each joke. I played around
> with $/ but not working.
> # I understand that $/ is set to new line by default. So this explains
> why I only get
> # the first line of each joke.
> # There must be a simple way to fix this? I appreciate any feedback.
This is not the real reason. You cant read 'line by line' because
your data items have more than one line. *If* you put an *empty*
new line behind each item, like
VAR1=15
VAR2=16
VAR=17
you could read the file in 'paragraph' mode like:
(pseudocode:)
$/ = ''; # set para mode
while( <CONFIGFILE> ) {
($ConfigVar, $Congif_value) = split /=/;
$ConfigValues{$ConfigVar} = $Congif_value;
}
and thats it. Otherwise (no empty line between items),
as your example suggests, you have to read in 'slurp'
mode (read the while file into one block), like:
...
my $fname= 'myconfigfile';
open( my $fh, '<', $fname ) or die "Can't read $!";
my $content;
{ local $/; $content = <$fh> }; # read in 'slurp' mode
close $fh;
...
I modified the style of the statements a blittle bit
to match a more comprehensive Perl style. The whole
file would now reside in $content, lets extract
it in one stroke (by regex).
...
my $reg = qr{
^(\w+)\s*=\s* # key follows ^
(.+ # complete text until $ (/m)
(?:\n [^=]* $)* # if available, take more lines w/out '='
) # (note the '$' anchor!)
}mx;
...
The regex has a second part in the second
(values) capture group: (?:\n [^=]* $)*
which reads entire lines if no '=' is
found in there.
Lets apply it:
...
my %Config = $content =~ /$reg/g;
...
You can print it as you used to do:
...
while ( my ($k,$v) = each %Config ) {
print "$k => $v\n\n";
}
...
Regards
M.
------------------------------
Date: 19 Jul 2007 08:13:47 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: new lines in the way
Message-Id: <5g8kprF3fic66U1@mid.dfncis.de>
<new2perl@gmail.com> wrote in comp.lang.perl.misc:
> Hi,
>
> I am trying to parse a text file that looks like this:
>
> __
> VAR1=15
> VAR2=16
> VAR=17
>
> FIRSTJOKE=this is my first joke. its isnt that funny but its still
> pretty good bla hbls dfd fsdf dsf sdfsd sd fdssd sdfdsf
> dsfdsfsdsdfsfsd
>
> SECONDJOKE=fdsf sdfdsf sdfdsfsdfdsfdsfdsfderew
> rweeeeeeeeeeeeeeeeeeeeeeeer2 wr ewre rewr er ewewrrewrew rewrewrew
> ewrew ewr ewr er ewr ewr er ewr we rew ew
> rewrewrewrewrewrererewrewrewrewrewrewrewrwerewrererewreerewrewrerererererer
>
> THIRDJOKE=notfunny
> ---
>
> My code is like this:
>
> #!/bin/perl
No warnings? No strict?
> #$/=undef;
>
> $conffile = "/myarea/myconfigfile";
>
> #read in config variables
> open ( CONFIGFILE, "< $conffile" ) || die "Can't open email template:
> $conffile \n";
>
> while ( <CONFIGFILE> ) {
> chop;
> if (/.*=.*/) {
> ($ConfigVar, $Congif_value) = split (/=/);
> $ConfigValues{$ConfigVar}=$Congif_value;
> }
>
> }
> close CONFIGFILE,
^
The comma is an error, it should be a semicolon. This is not the code
you ran. Don't re-type code, copy and paste it.
> while ( ($k,$v) = each %ConfigValues ) {
> print "$k => $v\n";
> }
>
>
> # It only prints out the first line of each joke.
Sure. You are only printing lines with a "=" in them. What did you
expect.
> I played around
> with $/ but not working.
"Not working" is no useful error description. What exactly have
you tried?
Your file format is irregular. Some of the assignments are followed
by an empty line (the JOKEs), others aren't (the VARs). So paragraph
mode won't help you much.
> # I understand that $/ is set to new line by default. So this explains
> why I only get
> # the first line of each joke.
> # There must be a simple way to fix this? I appreciate any feedback.
The unsuitable format doesn't allow for a really simple way. You'll
have to scan the file, looking for the next line with a "=" in it while
collecting other lines to form the value of the previous assignment.
You can only store away one key/value pair when you have seen the next
one. The last assignment must be treated outside the loop.
my %ConfigValues;
my ( $ConfigVar, $ConfigValue);
while ( <DATA> ) {
chop;
if (/.*=.*/) {
$ConfigValues{$ConfigVar} = $ConfigValue if defined $ConfigVar;
($ConfigVar, $ConfigValue) = split (/=/);
} else {
$ConfigValue .= $_;
}
}
$ConfigValues{$ConfigVar} = $ConfigValue if defined $ConfigVar;
close CONFIGFILE,
while ( my ($k,$v) = each %ConfigValues ) {
print "$k => $v\n";
}
__END__
VAR1=15
VAR2=16
VAR=17
FIRSTJOKE=this is my first joke. its isnt that funny but its still
pretty good bla hbls dfd fsdf dsf sdfsd sd fdssd sdfdsf
dsfdsfsdsdfsfsd
SECONDJOKE=fdsf sdfdsf sdfdsfsdfdsfdsfdsfderew
rweeeeeeeeeeeeeeeeeeeeeeeer2 wr ewre rewr er ewewrrewrew rewrewrew
ewrew ewr ewr er ewr ewr er ewr we rew ew
rewrewrewrewrewrererewrewrewrewrewrewrewrwerewrererewreerewrewrerererererer
THIRDJOKE=notfunny
Anno
------------------------------
Date: 19 Jul 2007 08:22:16 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: new lines in the way
Message-Id: <5g8l9oF3fic66U3@mid.dfncis.de>
<new2perl@gmail.com> wrote in comp.lang.perl.misc:
> Hi,
>
> I am trying to parse a text file that looks like this:
>
> __
> VAR1=15
> VAR2=16
> VAR=17
>
> FIRSTJOKE=this is my first joke. its isnt that funny but its still
> pretty good bla hbls dfd fsdf dsf sdfsd sd fdssd sdfdsf
> dsfdsfsdsdfsfsd
>
> SECONDJOKE=fdsf sdfdsf sdfdsfsdfdsfdsfdsfderew
> rweeeeeeeeeeeeeeeeeeeeeeeer2 wr ewre rewr er ewewrrewrew rewrewrew
> ewrew ewr ewr er ewr ewr er ewr we rew ew
> rewrewrewrewrewrererewrewrewrewrewrewrewrwerewrererewreerewrewrerererererer
>
> THIRDJOKE=notfunny
> ---
>
> My code is like this:
>
> #!/bin/perl
No warnings? No strict?
> #$/=undef;
>
> $conffile = "/myarea/myconfigfile";
>
> #read in config variables
> open ( CONFIGFILE, "< $conffile" ) || die "Can't open email template:
> $conffile \n";
>
> while ( <CONFIGFILE> ) {
> chop;
> if (/.*=.*/) {
> ($ConfigVar, $Congif_value) = split (/=/);
> $ConfigValues{$ConfigVar}=$Congif_value;
> }
>
> }
> close CONFIGFILE,
^
The comma is an error, it should be a semicolon. This is not the code
you ran. Don't re-type code, copy and paste it.
> while ( ($k,$v) = each %ConfigValues ) {
> print "$k => $v\n";
> }
>
>
> # It only prints out the first line of each joke.
Sure. You are only printing lines with a "=" in them. What did you
expect?
> I played around
> with $/ but not working.
"Not working" is no useful error description. What exactly have
you tried?
Your file format is irregular. Some of the assignments are followed
by an empty line (the JOKEs), others aren't (the VARs). So paragraph
mode won't help you much.
> # I understand that $/ is set to new line by default. So this explains
> why I only get
> # the first line of each joke.
> # There must be a simple way to fix this? I appreciate any feedback.
The unsuitable format doesn't allow for a really simple way. You'll
have to scan the file, looking for the next line with a "=" in it while
collecting other lines to form the value of the previous assignment.
You can only store away one key/value pair when you have seen the next
one. The last assignment must be treated outside the loop.
my %ConfigValues;
my ( $ConfigVar, $ConfigValue);
while ( <DATA> ) {
chop;
if (/.*=.*/) {
$ConfigValues{$ConfigVar} = $ConfigValue if defined $ConfigVar;
($ConfigVar, $ConfigValue) = split (/=/);
} else {
$ConfigValue .= $_;
}
}
$ConfigValues{$ConfigVar} = $ConfigValue if defined $ConfigVar;
close CONFIGFILE,
while ( my ($k,$v) = each %ConfigValues ) {
print "$k => $v\n";
}
__END__
VAR1=15
VAR2=16
VAR=17
FIRSTJOKE=this is my first joke. its isnt that funny but its still
pretty good bla hbls dfd fsdf dsf sdfsd sd fdssd sdfdsf
dsfdsfsdsdfsfsd
SECONDJOKE=fdsf sdfdsf sdfdsfsdfdsfdsfdsfderew
rweeeeeeeeeeeeeeeeeeeeeeeer2 wr ewre rewr er ewewrrewrew rewrewrew
ewrew ewr ewr er ewr ewr er ewr we rew ew
rewrewrewrewrewrererewrewrewrewrewrewrewrwerewrererewreerewrewrerererererer
THIRDJOKE=notfunny
Anno
------------------------------
Date: Thu, 19 Jul 2007 05:51:08 -0700
From: carlo.maier@netcologne.de
Subject: pid from startet process
Message-Id: <1184849468.415723.274020@57g2000hsv.googlegroups.com>
hi,
i am starting an exectuable on hp-ux (ActivePerl Build 817) from a
perl script and need to know the childs pid.
my $cmd="myexecutable -P parmfile "
my $pid=open(H, "${cmd} |");
print "\ttest: $_" while (<H>);
close(H);
The executable starts, but the pid i am getting is not right. The
executable writes a logfile with the pid as part of the logfile name.
After the executable returns, i want to check the logfile:
my $logfile="${logdir}/program_${pid}.log";
open(H,"< $logfile") or die "Can't open logfile '${logfile}': ($!)\n";
while (<H>) {
print if (/ENTRY/);
}
close (H);
For the reason that the pid, that i am trying to catch with the first
open-statement, is not correct, i have a problem to check the logfile.
What kind of reasons can be imagined, that the method "$pid=open(H, "$
{cmd} |");" doesn't supply the correct pid?
Does anybody know about a method that gives me the correct pid?
Thanks in adance,
carlo
------------------------------
Date: Thu, 19 Jul 2007 15:07:12 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: retrieving usenet messages III
Message-Id: <h9ou93lijg4sb32bq1fn2tn58i36jl1oeu@4ax.com>
On Wed, 18 Jul 2007 04:01:18 +0200, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:
>> #$nntp->authinfo($USER,$PASS) or die $!;
>--^
>Wake up! Be more careful before posting.
To the OP: and/or use a text editor that does syntax highlighting. It
will help you to "stay awake". Mine wants a space after # to recognize
it as a comment, and I generally stick to that because it's also
clearer: with one line it's only one more, easy, keystroke. With
several lines I take advantage of the editor's ability to comment and
uncomment a selected block of code, available with cheap keybindings.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 19 Jul 2007 01:06:10 -0700
From: Peter <mailbox@petervannes.nl>
Subject: STDOUT and STDERR redirection fails for forked process
Message-Id: <1184832370.203838.203600@i38g2000prf.googlegroups.com>
Hi,
Read the manpages, googled around, found some samples and followed
those to get it to work... but still fails..
What do i want? Simply, fork a command using the OPEN instruction,
redirect STDERR to STDOUT and capture the returncode of the executed
command.
I wrote the code wich is printed below, which works fine. Only output
from STDERR is not redirected to STDOUT but printed to the terminal
and the returncode is not captured. (So somehow redirected to STDOUT
but outside the open statement).
e.g. when the routine executes 'ls -Q' which sends the errormessage to
STDERR and a RC=2, the output from STDERR is printed to the terminal
and the returncode ($?) is 0.
Any ideas? suggestions?
Peter
Jul19 10:01:40 INF Data received from client "05794A6E5CD1122F ls -Q"
Jul19 10:01:40 DBG subroutine loccmd (15) (ls -Q)
Jul19 10:01:40 DBG Issuing command 'ls -Q'
ls: Not a recognized flag: Q
Usage: ls [-1ACFLNRabcdefgilmnopqrstuxE] [File...]
Jul19 10:01:40 DBG leaving subroutine loccmd passing values '0' '' ''
eval {
local $SIG{ALRM} = sub { die "Timed Out!\n" } ;
# set the alarm
alarm($timeout);
## Issue the command by forking the process and monitoring the
output
if (open STATUS, "$cmdstr 2>&1 |") {
while (<STATUS>) {
$result .= $_ ;
}
$errmsg = $! ;
$rcverror = $? ;
close STATUS ;
}
else {
$errmsg = "Fork failed for \'$cmdstr\'" ;
$rcverror = -2 ;
}
# reset the alarm
alarm(0) ;
$rcvtimeout = 0 ;
} ;
------------------------------
Date: Thu, 19 Jul 2007 03:09:41 -0700
From: Peter <mailbox@petervannes.nl>
Subject: STDOUT and STDERR redirection fails for forked process
Message-Id: <1184839781.378475.176120@q75g2000hsh.googlegroups.com>
Hi,
I am trying to redirect STDERR to STDOUT and catching the returncode
using the script below.
Currently every error is redirected to the terminal instead of to
STDERR or STDOUT, so i am not able to catch the output if it
originates from a process's STDERR.
Any ideas/suggestions why STDERR is not redirectoed ? (i assume that
the RC is always 0 because of the failed STDERR redirection).
## Issue the command by forking the process and monitoring the
output
if (open STATUS, "$cmdstr 2>&1 |") {
while (<STATUS>) {
$result .= $_ ;
}
close STATUS ;
$rcverror = $? >> 8;
$errmsg = $! ;
}
else {
$errmsg = "Fork failed for \'$cmdstr\'" ;
$rcverror = -2 ;
}
# reset the alarm
alarm(0) ;
$rcvtimeout = 0 ;
} ;
Peter
------------------------------
Date: 19 Jul 2007 09:43:34 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: STDOUT and STDERR redirection fails for forked process
Message-Id: <5g8q26F3fi15sU1@mid.dfncis.de>
Peter <mailbox@petervannes.nl> wrote in comp.lang.perl.misc:
> Hi,
>
> Read the manpages, googled around, found some samples and followed
> those to get it to work... but still fails..
>
> What do i want? Simply, fork a command using the OPEN instruction,
> redirect STDERR to STDOUT and capture the returncode of the executed
> command.
> I wrote the code wich is printed below, which works fine. Only output
> from STDERR is not redirected to STDOUT but printed to the terminal
> and the returncode is not captured. (So somehow redirected to STDOUT
> but outside the open statement).
>
> e.g. when the routine executes 'ls -Q' which sends the errormessage to
> STDERR and a RC=2, the output from STDERR is printed to the terminal
> and the returncode ($?) is 0.
>
> Any ideas? suggestions?
>
> Peter
>
> Jul19 10:01:40 INF Data received from client "05794A6E5CD1122F ls -Q"
> Jul19 10:01:40 DBG subroutine loccmd (15) (ls -Q)
> Jul19 10:01:40 DBG Issuing command 'ls -Q'
> ls: Not a recognized flag: Q
> Usage: ls [-1ACFLNRabcdefgilmnopqrstuxE] [File...]
> Jul19 10:01:40 DBG leaving subroutine loccmd passing values '0' '' ''
This is not the output of the code you showed. How can we help
you when you don't give us consistent information?
> eval {
> local $SIG{ALRM} = sub { die "Timed Out!\n" } ;
> # set the alarm
> alarm($timeout);
>
> ## Issue the command by forking the process and monitoring the
> output
> if (open STATUS, "$cmdstr 2>&1 |") {
> while (<STATUS>) {
> $result .= $_ ;
> }
> $errmsg = $! ;
> $rcverror = $? ;
>
> close STATUS ;
> }
> else {
> $errmsg = "Fork failed for \'$cmdstr\'" ;
> $rcverror = -2 ;
> }
>
> # reset the alarm
> alarm(0) ;
> $rcvtimeout = 0 ;
> } ;
That code is a mess. It isn't strict-safe. Why is everything wrapped
in an eval block? What is the value of $timeout? Or is it $rcvtimeout?
You are accessing $? too early. The return code is only put there after
close().
Reducing your code to the essentials (something *you* should have done),
this is what remains:
my $cmdstr = 'ls -9'; # -Q is a valid flag in some systems
open STATUS, '-|', "$cmdstr 2>&1";
print ">>> $_" while <STATUS>;
close STATUS;
print "retcode: $?\n";
exit;
This prints:
>>> ls: invalid option -- 9
>>> Try `ls --help' for more information.
retcode: 256
Note the ">>>" in front of the error message. It shows that the error
is not printed to stdout by the command but is caught and printed by
the perl program. The effect you complain about simply isn't there.
So what is this all about?
Anno
------------------------------
Date: Thu, 19 Jul 2007 15:00:11 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Using the split function
Message-Id: <uunu939h9hrvjlrjmq52nfpphca41mpqhv@4ax.com>
On Tue, 17 Jul 2007 17:36:34 -0500, Tad McClellan
<tadmc@seesig.invalid> wrote:
>>>> Ive deliberately left out the split function
>
>
>> Eighner sounds suspiciously like "a.....s"
> ^^^^^^^
> ^^^^^^^
>
>"abducts" ?
>
>"abscess" ?
>
>"assumes" ?
>
>"accuses"?
I thought it may have been something /^ass/, not "assumes", but I
can't think of anything significant... that "s" at the end defies my
poor English knowledge.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Thu, 19 Jul 2007 03:35:49 -0700
From: "Luis Angel Fdez. Fdez." <laffdez@gmail.com>
Subject: Why ($fh, $file) = mkstemps( "tmpfileXXXXXX", $suffix); doesn't work...
Message-Id: <1184841349.226038.258080@k79g2000hse.googlegroups.com>
Hi!
Why ($fh, $file) = mkstemps( "tmpfileXXXXXX", $suffix); doesn't work
as I think it has?
I have:
use File::Temp qw/ :mktemp /;
and then
my $template = "baysTempFileXXXX";
my ($fh_bays, $bays_temp) = mkstemps($template, ".info") || die("Could
not create temporary file.\n");
The program doesn't dies so I guess mkstemps creates the temp file,
but...
print $bays_temp."\n";
gives me:
Use of uninitialized value in concatenation (.) or string at ./
upload.pl line 87, <IF> line 6.
And line 87 is the line above (the one with the print).
That code is basically a copy'n'paste from
http://search.cpan.org/~jhi/perl-5.8.0/lib/File/Temp.pm so I think I'm
doing something wrong but I don't know what.
Thanks in advance.
Bye!
------------------------------
Date: 19 Jul 2007 10:49:26 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: Why ($fh, $file) = mkstemps( "tmpfileXXXXXX", $suffix); doesn't work...
Message-Id: <5g8ttmF3efcq6U1@mid.dfncis.de>
Luis Angel Fdez. Fdez. <laffdez@gmail.com> wrote in comp.lang.perl.misc:
> Hi!
>
> Why ($fh, $file) = mkstemps( "tmpfileXXXXXX", $suffix); doesn't work
> as I think it has?
>
> I have:
>
> use File::Temp qw/ :mktemp /;
>
> and then
>
> my $template = "baysTempFileXXXX";
> my ($fh_bays, $bays_temp) = mkstemps($template, ".info") || die("Could
You have a compound problem of context and precedence here. "||" has
higher precedence than "=", so this is interpreted as
my ($fh_bays, $bays_temp) =
( mkstemps($template, ".info") || die(...));
That puts mkstemp() into scalar context, which means it returns only
the file handle and not the name. So $bays_temp remains undefined,
as you have noted.
Use the lower-precedence "or" instead of "||" and all will be well.
Anno
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 661
**************************************