[28583] in Perl-Users-Digest
Perl-Users Digest, Issue: 9947 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 9 21:06:01 2006
Date: Thu, 9 Nov 2006 18:05:10 -0800 (PST)
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, 9 Nov 2006 Volume: 10 Number: 9947
Today's topics:
Re: Data plotting questions Nov. 2, 2006 jmg3000@gmail.com
How is @INC path constructed? <lax_reddy@hotmail.com>
Re: How is @INC path constructed? usenet@DavidFilmer.com
Re: How is @INC path constructed? <glennj@ncf.ca>
Re: How is @INC path constructed? <trwww@sbcglobal.net>
Re: How is @INC path constructed? <benmorrow@tiscali.co.uk>
How to monitor changes in a directory <lorenzo@diespammerhethurmans.com>
Re: How to monitor changes in a directory micmath@gmail.com
Re: How to monitor changes in a directory xhoster@gmail.com
Re: How to monitor changes in a directory <benmorrow@tiscali.co.uk>
Re: id3 tag reader and file name editor? usenet@DavidFilmer.com
Re: id3 tag reader and file name editor? <john@castleamber.com>
locating the nearest business day <cacheung@consumercontact.com>
Re: locating the nearest business day <sharkysharkshark@gmail.com>
Re: locating the nearest business day <tadmc@augustmail.com>
Re: Newbie perl question krakle@visto.com
Re: PERL can't open file for logging (world writable di yankeeinexile@gmail.com
Re: PERL can't open file for logging (world writable di <tadmc@augustmail.com>
Re: PERL can't open file for logging (world writable di <glex_no-spam@qwest-spam-no.invalid>
perl command line arguements <mrinalini.sukumar@gmail.com>
Re: perl exceptions and return value in finally block <glex_no-spam@qwest-spam-no.invalid>
perl threading; ->join; best method? <robert.waters@gmail.com>
Re: perl threading; ->join; best method? xhoster@gmail.com
Re: Strange behaviour <glex_no-spam@qwest-spam-no.invalid>
Re: Strange behaviour <gentoopower@yahoo.de>
Re: Strange behaviour <critterstown@googlemail.com>
Re: Strange behaviour <noreply@gunnar.cc>
Re: Strange behaviour <benmorrow@tiscali.co.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 9 Nov 2006 13:37:26 -0800
From: jmg3000@gmail.com
Subject: Re: Data plotting questions Nov. 2, 2006
Message-Id: <1163108246.382321.227490@b28g2000cwb.googlegroups.com>
edgrsprj wrote:
> [snip]
>
> One of the major goals here is to identify a language which scientists
> around the world would be willing to work with on a variety of projects.
Since you mention that, you might be pleased to have a look at PDL:
http://pdl.perl.org/ .
Also, regarding making plots with Perl, you might try out GD::Graph (
http://search.cpan.org/~bwarfield/GDGraph-1.4308/Graph.pm ).
---John
------------------------------
Date: 9 Nov 2006 13:22:01 -0800
From: "Lax" <lax_reddy@hotmail.com>
Subject: How is @INC path constructed?
Message-Id: <1163107321.626470.35300@m7g2000cwm.googlegroups.com>
Hi all,
Could someone give me a clue how the @INC path of a Perl installation
is constructed.
I'd installed a thirdparty package which was shipped with its own
version of Perl. Installing it put the software's bin folder in the
PATH variable first and it overrides any other Perl installation on the
machine.
The @INC path for invocation of any perl .exe from other installations,
always displays the package's bin first. Is there any way I could avoid
that from happening? The package's Perl is incompatible with a few of
my scripts.
I tried changing the system PATH env variable to put the desired Perl
installation bin folder first in the PATH. Even though, the PATH has
changed, the @INC doesnt seem to change.
I dont want to uninstall the software just on this account :)
Thanks for your time,
Lax
------------------------------
Date: 9 Nov 2006 13:29:44 -0800
From: usenet@DavidFilmer.com
Subject: Re: How is @INC path constructed?
Message-Id: <1163107784.498092.270000@k70g2000cwa.googlegroups.com>
Lax wrote:
> Could someone give me a clue how the @INC path of a Perl installation
> is constructed.
It's constructed when Perl is compiled. The only way to change it is to
recompile Perl and specify what you want. However, you may be
interested in alternatives:
perldoc -q @INC
How do I add a directory to my include path (@INC) at runtime?
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 9 Nov 2006 21:58:16 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: How is @INC path constructed?
Message-Id: <slrnel793o.ib2.glennj@smeagol.ncf.ca>
At 2006-11-09 04:22PM, "Lax" wrote:
> I'd installed a thirdparty package which was shipped with its own
> version of Perl. Installing it put the software's bin folder in the
> PATH variable first and it overrides any other Perl installation on the
> machine.
Why don't you delete (or rename) this offending perl interpreter?
--
Glenn Jackman
Ulterior Designer
------------------------------
Date: Thu, 09 Nov 2006 22:43:42 GMT
From: "Todd W" <trwww@sbcglobal.net>
Subject: Re: How is @INC path constructed?
Message-Id: <yaO4h.3387$IR4.3331@newssvr25.news.prodigy.net>
"Lax" <lax_reddy@hotmail.com> wrote in message
news:1163107321.626470.35300@m7g2000cwm.googlegroups.com...
> I'd installed a thirdparty package which was shipped with its own
> version of Perl. Installing it put the software's bin folder in the
> PATH variable first and it overrides any other Perl installation on the
> machine.
>
> The @INC path for invocation of any perl .exe from other installations,
> always displays the package's bin first. Is there any way I could avoid
> that from happening? The package's Perl is incompatible with a few of
> my scripts.
Then I would create a user specifically for running this app and alter only
the new user's path.
> I tried changing the system PATH env variable to put the desired Perl
> installation bin folder first in the PATH. Even though, the PATH has
> changed, the @INC doesnt seem to change.
Are you saying that:
/perl/I/use/perl -e 'print map "$_\n", @INC'
and
/perl/the/app/uses/perl -e 'print map "$_\n", @INC'
are the same?
I dont see that as a problem, unless the app installed over existing
modules. That would be rude.
Todd W.
------------------------------
Date: Thu, 9 Nov 2006 23:45:05 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: How is @INC path constructed?
Message-Id: <15rc24-1jg.ln1@osiris.mauzo.dyndns.org>
Quoth "Lax" <lax_reddy@hotmail.com>:
> Hi all,
> Could someone give me a clue how the @INC path of a Perl installation
> is constructed.
> I'd installed a thirdparty package which was shipped with its own
> version of Perl. Installing it put the software's bin folder in the
> PATH variable first and it overrides any other Perl installation on the
> machine.
>
> The @INC path for invocation of any perl .exe from other installations,
Given ^^^^, I'm assuming you're on
Win32, in which case perl (or at least, AS perl) will read some extra
entries for @INC from the registry, under HKLM\Software\Perl; all
versions of perl will also add entries to @INC from the PERLLIB and
PERL5LIB environment variables. It's possible this 3rd party piece of
software has set one of those up for itself; I would consider this a bug
in that piece of software.
> I tried changing the system PATH env variable to put the desired Perl
> installation bin folder first in the PATH. Even though, the PATH has
> changed, the @INC doesnt seem to change.
Just to check: can you post the results of
C:\> c:\full\path\to\MY\perl.exe -le"print for @INC"
and
C:\> c:\full\path\to\THEIR\perl.exe -le"print for @INC"
?
Ben
--
"If a book is worth reading when you are six, * benmorrow@tiscali.co.uk
it is worth reading when you are sixty." [C.S.Lewis]
------------------------------
Date: Thu, 09 Nov 2006 16:13:22 -0600
From: Lorenzo Thurman <lorenzo@diespammerhethurmans.com>
Subject: How to monitor changes in a directory
Message-Id: <6plc24-lep.ln1@Hedley.internal.thethurmans.com>
I want to monitor a directory for changes, but I don't want to poll
periodically to see if anything has changed. Is there a way to get
notifications in Perl about changes to a particular directory.
TIA
------------------------------
Date: 9 Nov 2006 15:38:10 -0800
From: micmath@gmail.com
Subject: Re: How to monitor changes in a directory
Message-Id: <1163115490.045102.91920@k70g2000cwa.googlegroups.com>
Lorenzo Thurman wrote:
> I want to monitor a directory for changes, but I don't want to poll
> periodically to see if anything has changed. Is there a way to get
> notifications in Perl about changes to a particular directory.
> TIA
This isn't really a problem that Perl alone can solve. Essentially you
must poll and there are a few ways to do that. crontab
http://en.wikipedia.org/wiki/Crontab can be used on Unixish systems to
schedule a script (Perl or otherwise) to run periodically and scan a
directory, for example.
On some systems, like Mac OS X, you can use "folder actions"
http://www.apple.com/applescript/folderactions/ to cause an AppleScript
to run whenever a folder is modified. There may be something similar on
Windows, I'm not sure.
In any case you will need to use something in addition to perl, and
that will be dependent on your OS.
-------------------------------------
Michael
http://www.perlcircus.org/
------------------------------
Date: 09 Nov 2006 23:53:28 GMT
From: xhoster@gmail.com
Subject: Re: How to monitor changes in a directory
Message-Id: <20061109185512.748$gR@newsreader.com>
Lorenzo Thurman <lorenzo@diespammerhethurmans.com> wrote:
> I want to monitor a directory for changes, but I don't want to poll
> periodically to see if anything has changed. Is there a way to get
> notifications in Perl about changes to a particular directory.
That is OS dependent. On linux, there is "fam". There seem to be some
Perl interfaces to it in CPAN, but I've never used them.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Thu, 9 Nov 2006 23:52:44 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: How to monitor changes in a directory
Message-Id: <cjrc24-1jg.ln1@osiris.mauzo.dyndns.org>
Quoth Lorenzo Thurman <lorenzo@diespammerhethurmans.com>:
> I want to monitor a directory for changes, but I don't want to poll
> periodically to see if anything has changed. Is there a way to get
> notifications in Perl about changes to a particular directory.
This depends on your OS. Under Win32 there is the Win32::ChangeNotify
module; I've never used it so I don't know how well it works. Under some
versions of IRIX and Linux you can run famd and use SGI::FAM. Under some
versions of Linux you can use the Linux::Inotify or Linux::Inotify2
modules.
Ben
--
"Faith has you at a disadvantage, Buffy."
"'Cause I'm not crazy, or 'cause I don't kill people?"
"Both, actually."
[benmorrow@tiscali.co.uk]
------------------------------
Date: 9 Nov 2006 11:39:04 -0800
From: usenet@DavidFilmer.com
Subject: Re: id3 tag reader and file name editor?
Message-Id: <1163101144.816153.184320@k70g2000cwa.googlegroups.com>
kaushik wrote:
> i have tried installing MP3::Tag module. but it is giving errors
Unless you have a development environment on your Windows box, you're
generally stuck with pre-built modules. Hopefully MP3::ID3v1 will meet
your needs:
http://aspn.activestate.com/ASPN/Modules?module_name=M&order=name&query_start=141
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: 9 Nov 2006 20:13:46 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: id3 tag reader and file name editor?
Message-Id: <Xns987690BF03083castleamber@130.133.1.4>
"kaushik" <sameerkumarkaushik@gmail.com> wrote:
> Hi all,
> i am new to perl scripting. actually i didnt feel the need for it till
> now. but now i think i need it. the problem is: i have a directory in
> which i have thousands of mp3 songs(all in one directory). The file
> names of the mp3files are incorrect. But the information in the ID3 tag
> are proper with title, album name and genre entries.
http://mp3tag.de/en/index.html
might save you a lot of trouble.
--
John Experienced Perl programmer: http://castleamber.com/
Perl help, tutorials, and examples: http://johnbokma.com/perl/
------------------------------
Date: 9 Nov 2006 15:58:42 -0800
From: "garhone" <cacheung@consumercontact.com>
Subject: locating the nearest business day
Message-Id: <1163116722.419845.82780@b28g2000cwb.googlegroups.com>
Hi,
I'm trying to figure out, given a date, which is the next closest
business day, AFTER the given date. I've tried looking at Date::Manip
and Date::Calc modules, but am getting nowhere.
I think it's a combination of functions that can achieve this, but so
far, I've only gotten
Date::Calc's Day_of_Week to see if today is a business day.
Any help would be appreciated.
Thanks.
------------------------------
Date: Fri, 10 Nov 2006 00:05:25 GMT
From: SSS <sharkysharkshark@gmail.com>
Subject: Re: locating the nearest business day
Message-Id: <newscache$1xmh8j$htf1$1@elise.onthenet.com.au>
garhone wrote:
> Hi,
>
> I'm trying to figure out, given a date, which is the next closest
> business day, AFTER the given date. I've tried looking at Date::Manip
> and Date::Calc modules, but am getting nowhere.
>
> I think it's a combination of functions that can achieve this, but so
> far, I've only gotten
> Date::Calc's Day_of_Week to see if today is a business day.
>
> Any help would be appreciated.
>
> Thanks.
>
Using Date::Manip, e.g. next business day after today:
DateCalc("today","+ 1 business days")
------------------------------
Date: Thu, 9 Nov 2006 19:52:13 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: locating the nearest business day
Message-Id: <slrnel7mqd.6k5.tadmc@tadmc30.august.net>
garhone <cacheung@consumercontact.com> wrote:
> I'm trying to figure out, given a date, which is the next closest
> business day, AFTER the given date.
http://search.cpan.org/~desiminer/Date-Business-1.2/Business.pm
$d->nextb(); # next business day
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 9 Nov 2006 14:50:44 -0800
From: krakle@visto.com
Subject: Re: Newbie perl question
Message-Id: <1163112644.674974.34580@m7g2000cwm.googlegroups.com>
On Nov 8, 8:50 am, lacla...@yahoo.com wrote:
> #!/usr/bin/perl
>
> $original ="http://admin:a...@192.168.1.1/cgi-bin/sysinfo.cgi";
> #$original ="README";
> open (FILE, $original);
> @lines=<FILE>;
> close FILE;
> print @lines;
> ...
> Any suggestions?
#!/usr/bin/perl -w
use strict;
use CGI;
use LWP::Simple;
my $cgi = new CGI;
my $original = "http://admin:a...@192.168.1.1/cgi-bin/sysinfo.cgi";
print $cgi->header("text/html");
print get($original);
------------------------------
Date: 09 Nov 2006 15:30:47 -0600
From: yankeeinexile@gmail.com
Subject: Re: PERL can't open file for logging (world writable directory Windows XP Home/ Active Perl / Apache)
Message-Id: <8764doxq7s.fsf@gmail.com>
Tad McClellan <tadmc@augustmail.com> writes:
> PGPS <premgrps@gmail.com> wrote:
>
> > X-No-Archive:Yes
>
>
> Why do you want to (attempt to) set no archive?
>
> (it does not work when you include it in the body like that, it
> needs to be in the headers.
> )
>
I usually parse that as "X-Ignore-Me: Yes"
I also think there is a specific exception for that specific header, to
allow for UA chains that do not allow you to alter the headers
properly.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer software consists of only two components: ones and
zeros, in roughly equal proportions. All that is required is to
sort them into the correct order.
------------------------------
Date: Thu, 9 Nov 2006 19:55:02 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: PERL can't open file for logging (world writable directory Windows XP Home/ Active Perl / Apache)
Message-Id: <slrnel7mvm.6k5.tadmc@tadmc30.august.net>
yankeeinexile@gmail.com <yankeeinexile@gmail.com> wrote:
> Tad McClellan <tadmc@augustmail.com> writes:
>> PGPS <premgrps@gmail.com> wrote:
>>
>> > X-No-Archive:Yes
>>
>>
>> Why do you want to (attempt to) set no archive?
>>
>> (it does not work when you include it in the body like that, it
>> needs to be in the headers.
>> )
>>
>
> I usually parse that as "X-Ignore-Me: Yes"
I have my newsreader parse that as "delete me automatically", but
it only works when it is in a header.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 09 Nov 2006 14:39:58 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: PERL can't open file for logging (world writable directory Windows XP Home/ Active Perl / Apache)
Message-Id: <45539226$0$508$815e3792@news.qwest.net>
PGPS wrote:
[...]
> open(LOGFILE, ">>/logs.html");
You have a file in your root ( '/' ) directory that's writable by
everyone??? Use the full path to the file.
------------------------------
Date: 9 Nov 2006 17:45:05 -0800
From: "mrinalini.sukumar@gmail.com" <mrinalini.sukumar@gmail.com>
Subject: perl command line arguements
Message-Id: <1163123104.940052.234520@f16g2000cwb.googlegroups.com>
Hi,
I have associate the perl executable to the .pl extension. The file
association works fine when I don't use the command line arguements,
but fails when I pass the command line arguements. When I execute the
same command by appending the perl command in the beginning, it works
fine. Does anyone know how to get around the problem? I am using perl
5.8.8 and I downloaded it from the activestate website.
------------------------------
Date: Thu, 09 Nov 2006 16:13:14 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: perl exceptions and return value in finally block
Message-Id: <4553a803$0$10297$815e3792@news.qwest.net>
rusland@scn.ru wrote:
> Hello !
>
> I need to know return value from try block in finally block.
>
> For example, I have code like this
> try {
> code 1...
> return x1 if ...
> code 2...
> return x2 if ...
> etc...
> }
> finally {
> my $ret = $how_to_get_return_value_from_try_block; #?
> };
>
> So finally block not only for exception processing, but also
> for processing of return code from try block.
>
> Is any build into perl mechanisms to let this value know
> in finally block? I study man page of Error.pm and not found
> any such possibility.
>
You can't "return" from a try.
my $ret;
try {
if( condition ) { $ret = 'abc' }
elsif( condition2 ) { $ret='lmnop'; }
}
------------------------------
Date: 9 Nov 2006 11:30:03 -0800
From: "robert.waters" <robert.waters@gmail.com>
Subject: perl threading; ->join; best method?
Message-Id: <1163100601.475817.300470@e3g2000cwe.googlegroups.com>
Hi,
I have a function that does a repetitive task, each task identified by
a unique index; I would like this task to be shared amongst a number of
threads. My question is, in what manner should I call 'join' in order
to be sure that each thread has completed it's task before the end of
the program?
My current logic is this:
--------------------------------------------------------------------
use LWP::UserAgent;
use HTTP::Request;
use threads;
use threads::shared;
my @threads;
my $threadcnt = 20;
my $unique_index : shared = 1;
$unique_index = 1;
my $top_index = 1000;
# CREATE ALL THE THREADS
for (my $i=0;$i<$threadcnt;$i++) {
$threads[$i] = threads->new('workerFunction', $i);
}
# JOIN ALL THREADS
foreach $thread (threads->list) {
$thread->join;
}
print "done.\n";
sub workerFunction {
my $threadindex = shift;
print STDERR "thread $threadindex starting...";
my $ua = LWP::UserAgent->new;
while ($unique_index < $top_index) {
my $url = "http://something.com/index.php?tid=".$unique_index++;
my $req = HTTP::Request->new(GET => $url);
my $resp = $ua->request($req);
print $resp->content;
}
}
-----------------------------------------
Basically, each thread shares a variable representing the index (and
increments it each time it is used).
After all the threads have been created, I iterate through the thread
list, calling join on each one in order. This iteration seems hackish
to me though; can this really be the right way to go about waiting for
the threads to finish? If thread 6 finishes first (which is definitely
possible), I am still waiting for threads 1 through 5 to finish before
I ever even check to see if thread 6 completes.
This technique, while working fine enough, just does not seem to be
"The Right Way" to do it; I would assume that the process of waiting
for threads to finish should be asynchronous.
Any suggestions?
Thank you-
Robert
------------------------------
Date: 09 Nov 2006 20:07:50 GMT
From: xhoster@gmail.com
Subject: Re: perl threading; ->join; best method?
Message-Id: <20061109150932.310$ZX@newsreader.com>
"robert.waters" <robert.waters@gmail.com> wrote:
> Hi,
>
> I have a function that does a repetitive task, each task identified by
> a unique index; I would like this task to be shared amongst a number of
> threads. My question is, in what manner should I call 'join' in order
> to be sure that each thread has completed it's task before the end of
> the program?
> My current logic is this:
> --------------------------------------------------------------------
> use LWP::UserAgent;
> use HTTP::Request;
> use threads;
> use threads::shared;
>
> my @threads;
> my $threadcnt = 20;
>
> my $unique_index : shared = 1;
> $unique_index = 1;
> my $top_index = 1000;
>
> # CREATE ALL THE THREADS
> for (my $i=0;$i<$threadcnt;$i++) {
>
> $threads[$i] = threads->new('workerFunction', $i);
>
> }
>
> # JOIN ALL THREADS
> foreach $thread (threads->list) {
>
> $thread->join;
>
> }
>
> print "done.\n";
>
> sub workerFunction {
>
> my $threadindex = shift;
>
> print STDERR "thread $threadindex starting...";
>
> my $ua = LWP::UserAgent->new;
>
> while ($unique_index < $top_index) {
>
> my $url =
> "http://something.com/index.php?tid=".$unique_index++;
This doesn't seem safe to me. unique_index could change between the
while and the url construction. Also, if two threads create the url
at the same time, they might both get the same url, and the next url would
get skipped. You should lock the variable.
while (1) {
{
lock($unique_index);
my $private = $unique_index++;
} # release the lock;
last if $unique_index >= $top_index
or you could use Thread::Queue instead of all of this stuff.
...
> Basically, each thread shares a variable representing the index (and
> increments it each time it is used).
> After all the threads have been created, I iterate through the thread
> list, calling join on each one in order. This iteration seems hackish
> to me though; can this really be the right way to go about waiting for
> the threads to finish?
Yep.
> If thread 6 finishes first (which is definitely
> possible), I am still waiting for threads 1 through 5 to finish before
> I ever even check to see if thread 6 completes.
So what?
> This technique, while working fine enough, just does not seem to be
> "The Right Way" to do it; I would assume that the process of waiting
> for threads to finish should be asynchronous.
You could use is_joinable in threads.pm newer than 1.34, or for older
threads.pm then use Thread::State. But in the given situation, I don't
see how this would be an improvement. Making the change would be more
hackish then just leaving it as it is.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Thu, 09 Nov 2006 14:33:39 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Strange behaviour
Message-Id: <455390ab$0$508$815e3792@news.qwest.net>
Richard wrote:
> Why does isn't my function executed in this context:
>
>
> # does not work
> my $doc = XMLin($configfile) or die Notifier::Info("ERROR: Can't open
> $configfile");
>
> # works if I change the above line in my perl script
> Notifier::Info("blablub");
> my $doc = XMLin($configfile)
You'd have seen the same behavior even without using your class.
Put an eval around it. XMLin will croak/die the file doesn't exist.
eval {
my $doc = XMLin($configfile);
#.. more XML::Simple methods...
};
if ( $@ )
{
Notifier::Info($@);
die( $@ );
}
Or redefine $SIG{__DIE__}.
------------------------------
Date: Thu, 09 Nov 2006 21:58:24 +0100
From: Gentoopower <gentoopower@yahoo.de>
Subject: Re: Strange behaviour
Message-Id: <ej04pf$ee1$1@online.de>
Gunnar Hjalmarsson wrote:
> Richard wrote:
>>
>> # does not work
>> my $doc = XMLin($configfile) or die Notifier::Info("ERROR: Can't open
>> $configfile");
>
> Pls define "does not work".
>
> Maybe XMLin() returns a true value even if it cannot read the file? In
> that case, checking whether the return value is true isn't an adequate
> error check.
>
No in my case it dies, because the file doesn't exist.
Of course I did a simple test and replaced:
.. or die Notifier::Info("ERROR: Can't open $configfile");
with:
or die print "..";
which works:-)
But J.Gleixner replied with a resonable solution, which I'm going to
checkout. I'm still don't exactly understand, why:
or die print "..."; # works
and
or die Notifier::Info("..."); # doesn't
but calling Notifier::Info("...") within normal code works.
------------------------------
Date: Thu, 09 Nov 2006 22:33:34 +0100
From: Richard <critterstown@googlemail.com>
Subject: Re: Strange behaviour
Message-Id: <ej06v8$igq$1@online.de>
J. Gleixner schrieb:
> Richard wrote:
>> Why does isn't my function executed in this context:
>>
>>
>> # does not work
>> my $doc = XMLin($configfile) or die Notifier::Info("ERROR: Can't open
>> $configfile");
>>
>> # works if I change the above line in my perl script
>> Notifier::Info("blablub");
>> my $doc = XMLin($configfile)
>
> You'd have seen the same behavior even without using your class.
Darn you are right, when I first tested some of my stuff I used used it
with an open file and there a print worked:-)
Then I did lots of coding and didn't pay attention to it anymore.
>
> Put an eval around it. XMLin will croak/die the file doesn't exist.
>
> eval {
> my $doc = XMLin($configfile);
> #.. more XML::Simple methods...
> };
> if ( $@ )
> {
> Notifier::Info($@);
> die( $@ );
> }
>
> Or redefine $SIG{__DIE__}.
>
>
Perfect answer, A+ :-)
Thanks, now I'm all set. a simple print just wasn't sufficient to me
since I have to send mails etc. in case something goes wrong(dies).
------------------------------
Date: Fri, 10 Nov 2006 00:00:45 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Strange behaviour
Message-Id: <4rhqcrFrfej8U1@mid.individual.net>
Gentoopower wrote:
> Gunnar Hjalmarsson wrote:
>>Richard wrote:
>>>
>>># does not work
>>>my $doc = XMLin($configfile) or die Notifier::Info("ERROR: Can't open
>>>$configfile");
>>
>>Pls define "does not work".
>>
>>Maybe XMLin() returns a true value even if it cannot read the file? In
>>that case, checking whether the return value is true isn't an adequate
>>error check.
>
> No in my case it dies, because the file doesn't exist.
> Of course I did a simple test and replaced:
>
> .. or die Notifier::Info("ERROR: Can't open $configfile");
>
> with:
>
> or die print "..";
>
> which works:-)
The latter does probably not "work" the way you think it does.
You don't understand the meaning of using 'or' that way, do you? You can
do so if the function _returns_ a true value at success, but only at
success. That's probably not the case with XMLin(), which - assuming we
are talking about XML::Simple::XMLin() - returns a reference according
to the POD.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 9 Nov 2006 23:32:47 +0000
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Strange behaviour
Message-Id: <vdqc24-1jg.ln1@osiris.mauzo.dyndns.org>
Quoth "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>:
> Richard wrote:
> > Why does isn't my function executed in this context:
> >
> >
> > # does not work
> > my $doc = XMLin($configfile) or die Notifier::Info("ERROR: Can't open
> > $configfile");
> >
> > # works if I change the above line in my perl script
> > Notifier::Info("blablub");
> > my $doc = XMLin($configfile)
>
> You'd have seen the same behavior even without using your class.
>
> Put an eval around it. XMLin will croak/die the file doesn't exist.
>
> eval {
> my $doc = XMLin($configfile);
This variable is scoped over the eval only, so it won't exist outside.
> #.. more XML::Simple methods...
> };
> if ( $@ )
> {
> Notifier::Info($@);
> die( $@ );
> }
Since eval returns undef when it catches an exception, this can be
simplified to
my $doc = eval { XMLin($configfile) }
or die "XMLin('$configfile') failed: $@";
Ben
--
"If a book is worth reading when you are six, * benmorrow@tiscali.co.uk
it is worth reading when you are sixty." [C.S.Lewis]
------------------------------
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 V10 Issue 9947
***************************************