[18026] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 186 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 31 18:11:35 2001

Date: Wed, 31 Jan 2001 15:10:25 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <980982624-v10-i186@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 31 Jan 2001     Volume: 10 Number: 186

Today's topics:
    Re: Help Reg expr to handle variables safely? perlop co nobull@mail.com
        how do I get an IP address? <storm@isbangelijk.com>
    Re: how do I get an IP address? jimjim123@my-deja.com
    Re: how do I get an IP address? <joe+usenet@sunstarsys.com>
        How do you set a timer on a script? <cam@home.com>
    Re: How do you set a timer on a script? <bcaligari@my-deja.com>
        opendir() / readdir() Fail When Called Via CGI jerry@cynicproductions.com
    Re: opendir() / readdir() Fail When Called Via CGI <tony_curtis32@yahoo.com>
    Re: opendir() / readdir() Fail When Called Via CGI <arthur.haas@westgeo.com>
        perl report generation <motivusNO@SPAMhotmail.com>
    Re: perl report generation <bcaligari@my-deja.com>
    Re: printf and leading zeros <iltzu@sci.invalid>
    Re: printf and leading zeros <russ_jones@rac.ray.com>
    Re: printing array of hashes <motivusNO@SPAMhotmail.com>
    Re: qr and backreferences (Gwyn Judd)
    Re: qr and backreferences (Gwyn Judd)
    Re: qr and backreferences (Gwyn Judd)
    Re: RegExp: Find anything except... <iltzu@sci.invalid>
        Sed in Perl Script Versus Sed in Unix smnsn@my-deja.com
    Re: Sed in Perl Script Versus Sed in Unix <bcaligari@my-deja.com>
    Re: Seeking timezone conversion advice <ddunham@redwood.taos.com>
        Should this code work? (Steve)
    Re: Should this code work? <godzilla@stomp.stomp.tokyo>
    Re: Should this code work? (Steve)
    Re: Should this code work? (Gwyn Judd)
    Re: Should this code work? <godzilla@stomp.stomp.tokyo>
        simple split question.... <aa533@chebucto.ns.ca>
    Re: simple split question.... nobull@mail.com
    Re: simple split question.... <sumus@aut.dk>
    Re: Sorting in NT like in Unix (Gwyn Judd)
    Re: Sorting in NT like in Unix <chrisw@dynamite.com.au>
        strange behaviour of Net::SMTP <nospam@nospam.com>
    Re: strange behaviour of Net::SMTP <bcaligari@my-deja.com>
        trap die <ducateg@info.bt.co.uk>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 31 Jan 2001 19:36:23 +0000
From: nobull@mail.com
Subject: Re: Help Reg expr to handle variables safely? perlop confusing.
Message-Id: <u9elxjo6o8.fsf@wcl-l.bham.ac.uk>

chuckk@monmouth.com writes:

> I've just read the perlop section of the faq on quoting.
> But I'm still confused about special charaters in the string like


> Say I have a variable that contains the following:
> $a='mydir/myfile$_&?.txt';
> $b='$_&?';
> $c='^&*"';
> 
> $d= $a;
> $d =~ s,\Q$b\E,\Q$c\E,g;
> 
> IS THIS THE SAFEST SIMPLEST WAY - OR WHAT OTHER WAYS COULD I DO THIS?

Yes, but IHMO it looks untidy.

Well IMHO comma is a poor choice of delimiter for s///g - especially
if there's no reason not to use the forward slash.  Oh, and the \E are
redundant.

 $d =~ s/\Q$b/\Q$c/g;

This is semantically exaclty the same as your solution.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


------------------------------

Date: Wed, 31 Jan 2001 21:37:18 GMT
From: "Storm" <storm@isbangelijk.com>
Subject: how do I get an IP address?
Message-Id: <iA%d6.311379$MA1.10182911@afrodite.telenet-ops.be>

how do I get an ip addres of my network card?

this must be os independant
you may not use the program "ipconfig.exe" and then parse every line until
you have found the ip

has perl a function to do this?




------------------------------

Date: Wed, 31 Jan 2001 22:48:50 GMT
From: jimjim123@my-deja.com
Subject: Re: how do I get an IP address?
Message-Id: <95a4of$8a0$1@nnrp1.deja.com>

Aye, use the Sys::Hostname which gives you the hostname, then you can
query a DNS to get the IP....  If you consult perldoc, it returns the
following useful information...

           use Socket;
           use Sys::Hostname;
           my $host = hostname();
           my $addr = inet_ntoa(scalar gethostbyname($host ||
'localhost'));

Cheers!

H.

In article <iA%d6.311379$MA1.10182911@afrodite.telenet-ops.be>,
  "Storm" <storm@isbangelijk.com> wrote:
> how do I get an ip addres of my network card?
>
> this must be os independant
> you may not use the program "ipconfig.exe" and then parse every line
until
> you have found the ip
>
> has perl a function to do this?
>
>


Sent via Deja.com
http://www.deja.com/


------------------------------

Date: 31 Jan 2001 18:00:31 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: how do I get an IP address?
Message-Id: <m3d7d38gz4.fsf@mumonkan.sunstarsys.com>

"Storm" <storm@isbangelijk.com> writes:

> how do I get an ip addres of my network card?
                  ^^^^^^^^^
% perldoc -q "ip addres"

> this must be os independant

?!?

> you may not use the program "ipconfig.exe" and 
> then parse every line until you have found the ip
> 
> has perl a function to do this?

Yes; you may use the following program and read 
every line until you have found your answer.

#!/usr/bin/perl -w
use strict;

sub FAQ;
*FAQ = [qw(perldoc perl perlfaq perlfaq9)];

sub newbie {

    *UNIVERSAL::AUTOLOAD =  sub {
	pop() -> (), $UNIVERSAL::AUTOLOAD, \& newbie
    };

    *FAQ = sub {system "perldoc", *FAQ->[${*FAQ}++]; \& newbie};
}


fetch the Perl networking FAQ for a curious newbie

__END__

-- 
Joe Schaefer


------------------------------

Date: Wed, 31 Jan 2001 21:34:29 GMT
From: "cam" <cam@home.com>
Subject: How do you set a timer on a script?
Message-Id: <Fx%d6.49531$_8.1469389@news1.rdc1.bc.home.com>

Hi:

I have a news grabber on my site that I wrote in perl. But I want the script
to get the news at a specific time, then cache it to a data file so that the
page will load a little faster (won't need to run the LWP script everytime a
page loads - will have the data on a data file on the server).

How can I get a perl script to execute at a specific time?
For example:

At 6am -> run this script "parseNews.pl"


Thanks
Cam
cam@home.com




------------------------------

Date: Wed, 31 Jan 2001 22:13:56 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
To: cam@home.com
Subject: Re: How do you set a timer on a script?
Message-Id: <95a2ms$6aj$1@nnrp1.deja.com>

In article <Fx%d6.49531$_8.1469389@news1.rdc1.bc.home.com>,
  "cam" <cam@home.com> wrote:

> How can I get a perl script to execute at a specific time?
> For example:
>
> At 6am -> run this script "parseNews.pl"
>

using unix:
man cron

using win2000
help at     (but i have never tried it)

Brendon


Sent via Deja.com
http://www.deja.com/


------------------------------

Date: Wed, 31 Jan 2001 19:14:25 GMT
From: jerry@cynicproductions.com
Subject: opendir() / readdir() Fail When Called Via CGI
Message-Id: <959o67$s1q$1@nnrp1.deja.com>

Dear Readers:

I'm using a simple script called from a browser to read the contents of
a directory. It's very easy, like this:

opendir(DIRHANDLE, "$somepath");
@files = readdir(DIRHANDLE);
closedir(DIRHANDLE);

This works fine from the command line, but simply ends with no output
when called via the browser. No error messages. Nothing. It simply
ends. It's not likely a permissions error because the script has read
and write access to the directory.

This is done under WinNT using IIS 4. Has anyone else had this happen?
Any advice is way appreciated. Thanks.

rch1m3d3s


Sent via Deja.com
http://www.deja.com/


------------------------------

Date: 31 Jan 2001 13:34:43 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: opendir() / readdir() Fail When Called Via CGI
Message-Id: <87wvbbsegc.fsf@limey.hpcc.uh.edu>

>> On Wed, 31 Jan 2001 19:14:25 GMT,
>> jerry@cynicproductions.com said:

> Dear Readers: I'm using a simple script called from a
> browser to read the contents of a directory. It's very
> easy, like this:

> opendir(DIRHANDLE, "$somepath"); @files =
> readdir(DIRHANDLE); closedir(DIRHANDLE);

You're not where you think you are.

Write a CGI program which just prints out its current
directory.  You might be surprised.

    perldoc Cwd

hth
t
-- 
Eih bennek, eih blavek.


------------------------------

Date: 31 Jan 2001 14:39:10 -0600
From: Art Haas <arthur.haas@westgeo.com>
Subject: Re: opendir() / readdir() Fail When Called Via CGI
Message-Id: <lru26fihht.fsf@h130p254.wg.waii.com>

jerry@cynicproductions.com writes:

> Dear Readers:
> 
> I'm using a simple script called from a browser to read the contents of
> a directory. It's very easy, like this:
> 
> opendir(DIRHANDLE, "$somepath");
> @files = readdir(DIRHANDLE);
> closedir(DIRHANDLE);
> 
> This works fine from the command line, but simply ends with no output
> when called via the browser. No error messages. Nothing. It simply
> ends. It's not likely a permissions error because the script has read
> and write access to the directory.
> 

Always check `$!'! It's also wise to `use strict;' too.

use strict;
my $somepath = '/path/you/are/interested/in';
opendir(DIRHANDLE,$somepath) || die "Can't open `$somepath'! $!\n";
my @files = readdir(DIRHANDLE);
closedir(DIRHANDLE) || die "Closedir failed! $!\n";

It's possibly a permission issue, and `$!' should help you pinpoint it.

-- 
###############################
# Art Haas
# (713) 689-2417
###############################


------------------------------

Date: Wed, 31 Jan 2001 11:54:30 -0800
From: "B McDonald" <motivusNO@SPAMhotmail.com>
Subject: perl report generation
Message-Id: <35_d6.35$xR1.46061@news.pacbell.net>


hi. i am curious about the utility of perl's report generation capability --
namely format. do people use this? is it worth my time to learn? or are
there better ways to generate reports?

what about a way to generate html-ized reports in perl?

thanks,

brian





------------------------------

Date: Wed, 31 Jan 2001 20:21:02 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: perl report generation
Message-Id: <959s32$vtb$1@nnrp1.deja.com>

In article <35_d6.35$xR1.46061@news.pacbell.net>,
  "B McDonald" <motivusNO@SPAMhotmail.com> wrote:
>
> hi. i am curious about the utility of perl's report generation
capability --
> namely format. do people use this? is it worth my time to learn? or
are
> there better ways to generate reports?
>
> what about a way to generate html-ized reports in perl?
>

I (ab)use Here documents heavily.  I also find it very convenient to
iterate/print html table rows when pushing out stats, usage reports,
etc.

B


Sent via Deja.com
http://www.deja.com/


------------------------------

Date: 31 Jan 2001 19:58:16 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: printf and leading zeros
Message-Id: <980970918.19798@itz.pp.sci.fi>

In article <t7go7oms60ui6e@corp.supernews.com>, Chris Stith wrote:
>
>Does your answer look anything like this?
>
>my $number = 0.33;
>my $number_like_string = sprintf("%s", $number);
>$number_like_string =~ s/0(?=\.)//;
>print "$number_like_string\n";

I hope not.  That second line is an expensive no-op, and the regexp
probably needs anchoring to stop "10.05" becoming "1.05".

  (my $string = $number) =~ s/^0\././;

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"Cats, I presume, are on topic just because they're cats and refuse to
 be left out of the conversation."  -- Zeborah in r.a.sf.c

Please ignore Godzilla and its pseudonyms - do not feed the troll.


------------------------------

Date: Wed, 31 Jan 2001 16:09:25 -0600
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: printf and leading zeros
Message-Id: <3A788D15.355331EB@rac.ray.com>

Ilmari Karonen wrote:
> 
> In article <t7go7oms60ui6e@corp.supernews.com>, Chris Stith wrote:
> >
> >Does your answer look anything like this?
> >
> >my $number = 0.33;
> >my $number_like_string = sprintf("%s", $number);
> >$number_like_string =~ s/0(?=\.)//;
> >print "$number_like_string\n";
> 
> I hope not.  That second line is an expensive no-op, and the regexp
> probably needs anchoring to stop "10.05" becoming "1.05".
> 
>   (my $string = $number) =~ s/^0\././;
> 

Sure, those methods will work, but I was asking about using printf
only, which it looks to me like you just flat can't do.

But thanks for the reply anyway!






-- 
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747

Cacatne ursus in sylvis? - Ovid


------------------------------

Date: Wed, 31 Jan 2001 11:50:38 -0800
From: "B McDonald" <motivusNO@SPAMhotmail.com>
Subject: Re: printing array of hashes
Message-Id: <r1_d6.34$xR1.45234@news.pacbell.net>


"Michael Carman" <mjcarman@home.com> wrote in message
news:3A7827C9.C633E377@home.com...
> B McDonald wrote:
> >
> > "Peter Sundstrom" <peter.sundstrom@eds.com> wrote:
> >>
> >> "Jürgen Exner" <juex@deja.com> wrote:
> >>>
> >>> By its very definition a hash does not have an order (well, there
> >>> is an implementation-defined order but that is pretty much useless
> >>> for all practical purposes).
>
> Furthermore, it could change without notice in future versions of Perl.
>
> >>> Therefore it cannot preserve any order.
> >>>
> >>> If you want an order, then you must use an array (or pointer
> >>> lists or whatever).
> >>
> >> You can use the Tie::IxHash
> >> http://search.cpan.org/search?mode=module&query=IXhash
> >>
> >
> > Thank you for the tip, Peter. This might be a naive question, but
> > what is the computational penalty of using such a module? I am
> > wondering if it is too expensive for my application.
>
> It's significant -- observe:
>
> #!/usr/local/bin/perl5 -w
> use strict;
> use Benchmark;
> use Tie::IxHash;
>

Thank you for this significant insight into, not only my question, but into
benchmarking perl programs in general. I was heretofore unaware of the
Benchmark module.

Thanks for the example!

Brian




------------------------------

Date: Wed, 31 Jan 2001 21:04:24 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: qr and backreferences
Message-Id: <slrn97gveo.9u0.tjla@thislove.dyndns.org>

I was shocked! How could Uri Guttman <uri@sysarch.com>
say such a terrible thing:

>i think he means something like (bogus syntax):
>
>	$qr = /(.)\-1/ ;
>
>the concept is that you are doing a relative count to the wanted
>backref. this can work inside the qr or in the larger regex as well.

Yeah that's what I meant.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Flugg's Law:
	When you need to knock on wood is when you realize that the
	world is composed of vinyl, naugahyde and aluminum.


------------------------------

Date: Wed, 31 Jan 2001 21:05:49 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: qr and backreferences
Message-Id: <slrn97gvhd.9u0.tjla@thislove.dyndns.org>

I was shocked! How could Abigail <abigail@foad.org>
say such a terrible thing:

>You mean, as in $qr = /(.)\2/;?

No because \2 gives the 2'nd from the start of the regex. What I want is
something to say "give me the second counting back from the current
point".

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
GOOD

adj. Sensible, madam, to the worth of this present writer. Alive, sir,
to the advantages of letting him alone.


------------------------------

Date: Wed, 31 Jan 2001 21:10:38 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: qr and backreferences
Message-Id: <slrn97gvqe.9u0.tjla@thislove.dyndns.org>

I was shocked! How could Rafael Garcia-Suarez <rgarciasuarez@free.fr>
say such a terrible thing:

>Thinking about this, I believe Abigail is right.

Thinking on the example you gave (qr/\1/) I think it should indeed be
reported. I'm not sure what the correct behaviour should be but I don't
think backreferences should only refer to matched brackets in the
current regex. Otherwise, what can you do when you want to refer to
backreferences in an enclosing regex? Maybe there should be an error at
runtime instead of when the regex is compiled if the thing refers to a
non-existant set of brackets.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The use of money is all the advantage there is to having money.
-B. Franklin


------------------------------

Date: 31 Jan 2001 19:49:57 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: RegExp: Find anything except...
Message-Id: <980969973.16962@itz.pp.sci.fi>

In article <959aht$e80$1@nnrp1.deja.com>, Costis Vezeridis wrote:
>"Find anything from the last % or >, until the next % or <, making sure
>there is no % or < in between".

TIMTOWTDI.  Using split() isn't the most memory efficient one, but
it's nice and simple:

  my @chunks = split /(<[^>]*>|%[^%]*%)/, $string;

>I need this because the ? for the non-greedy search does not always
>seem to work reliably.

use PSI::ESP;

How does it "not always seem to work reliably"?  Does it perhaps fail
to match more than one line?  Did you write ".*?"?  Did you forget /s?

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The same teacher once took a class to the river to show them the effects of
 lithium in water.  The problem is that generally when someone throws something
 into the water, it's bread for the ducks.  His students got an unexpected
 lesson on the effects of lithium in duck."  -- Zeborah in r.a.sf.c

Please ignore Godzilla and its pseudonyms - do not feed the troll.


------------------------------

Date: Wed, 31 Jan 2001 21:18:09 GMT
From: smnsn@my-deja.com
Subject: Sed in Perl Script Versus Sed in Unix
Message-Id: <959ve6$3ak$1@nnrp1.deja.com>

     I've written a script that pipes the output from a Unix command,
and attempts to rearrange the fields before storing the output.  I've
captured the performance right here:

     [] cat Hmm
     #!/usr/bin/perl

     $Jqz = `echo "abcdef" | sed "s/cd//" | sed "s/\(..\)\(..\)/\2\1/"`;
     chop ($Jqz);
     print "Jqz == \"$Jqz\".\n";
     [] Hmm
     Jqz == "abef".
     [] echo "abcdef" | sed "s/cd//" | sed "s/\(..\)\(..\)/\2\1/"
     efab
     []

Note that when I execute the "echo" command piped to "sed" on my Unix
platform I get the results I want; the "ab" and the "ef" trade places.
However, when I try it in the Perl script, the "cd" does get removed,
but the "ab" and the "ef" don't trade places.  Anybody know why?

                                ---Kevin
                                   Reverence the eternal.


Sent via Deja.com
http://www.deja.com/


------------------------------

Date: Wed, 31 Jan 2001 22:45:19 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: Sed in Perl Script Versus Sed in Unix
Message-Id: <95a4ht$7vk$1@nnrp1.deja.com>

In article <959ve6$3ak$1@nnrp1.deja.com>,
  smnsn@my-deja.com wrote:
>      I've written a script that pipes the output from a Unix command,
> and attempts to rearrange the fields before storing the output.  I've
> captured the performance right here:
>
>      [] cat Hmm
>      #!/usr/bin/perl
>
>      $Jqz = `echo "abcdef" | sed "s/cd//" | sed "s/\(..\)\(..\)/\2
\1/"`;
>      chop ($Jqz);
>      print "Jqz == \"$Jqz\".\n";
>      [] Hmm

Besides an issue with quoting character escaping, it is worth
poiting out that perl has an inbuilt s/// operator similar to
(in fact more powerful) than sed's.

B


Sent via Deja.com
http://www.deja.com/


------------------------------

Date: Wed, 31 Jan 2001 19:29:55 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Seeking timezone conversion advice
Message-Id: <TIZd6.80476$Wq1.33936855@nnrp5-w.sbc.net>

James Weisberg <chadbour@wwa.com> wrote:

>    Anyway, thanks to those who suggested I try setting $ENV{TZ} and
> use Time::Local. I thought about that originally but I was uncertain
> as to how reliable that method would be. The SCO Enterprise (yeah,
> yeah, I know) OS I tried it on makes the change right away so it
> worked fine. However, I think the two cooperating functions I had
> described might work much faster without the need for various time
> system calls.

'time system calls'?  You're not changing anything on the machine other
than that one ENV variable.  You're certainly not changing the clock.

It's just that whenever you use localtime (or timelocal) the TZ variable
is used for the conversion.

 Basically, the isdst() function I proposed could use
> another hash which has hardwired the DST dates for several years. 

That information is already in the OS in the zoneinfo files.  Noone
wants to reenter that information into another area (possibly
incorrectly, and harder to change in the future if need be).

> For example, I could have an entry:
>    $DST{2001} = [20010401, 20011028];

>    which says that Spring Foreword occurs on April 1st 2001 (the
> first Sunday in April) and Fall Backword occurs on October 28th
> 2001 (the last Sunday in October).  
>    Then someone could write:

>    isdst($date, $time, $tz);

What is the difference between $date and $time?  You already have that
function as part of localtime()..

$ENV{TZ} = $tz;
$isdst = (localtime($time))[8];

>    and if $date < $DST{2001}[0] || $date > $DST{2001}[1], then we
> are not in Daylight Savings Time (regardless of timezone). More work
> is needed for boundary conditions, but so far I've yet to even need
> a time system call [isdst() is not even called unless one timezone
> uses DST and the other does not.] 
>    However, unless someone wants to comment specifically on these
> ideas, I might just take the path of least resistance and use the
> ENV{TZ} method even though I find it "hokey" to ying-yang my TZ.

I think you're thinking that TZ is somehow more heavyweight or more
important than something like PATH.  Yes it affects the behavior of
other programs, but it's not a 'time system call'.

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
      < Please move on, ...nothing to see here,  please disperse >


------------------------------

Date: Wed, 31 Jan 2001 20:03:52 GMT
From: pawsindoors@hotmail.com (Steve)
Subject: Should this code work?
Message-Id: <3a786c59.37216101@news.freeserve.net>

Could someone please help me to understand why the following does not
work:

$this_directory = "$form_data{'selected_directory'}";  # User form 
$path_to_myfile = '/home/path/to/'.$this_directory.'/myfile.txt';

open(LOGFILE, "<$path_to_myfile") || &errormesssage;
    flock(LOGFILE, 2);
       @catalog = <LOGFILE>;  # Reads the file okay
    flock(LOGFILE, 8);
close(LOGFILE);

foreach $catalog(@catalog)
   {
   @check_line = split(/\|/,$catalog);

   if ($check_line[1] ne "String to match")
      {
      push(@updated_catalog,$catalog);  # Updates the new array okay
      }
   }

open(LOGFILE, ">$path_to_myfile") || &errormesssage;
   flock(LOGFILE, 2);
     foreach $catalog(@updated_catalog)
       {
       print LOGFILE "$catalog";  # Does not write back to the file
       }
   flock(LOGFILE, 8);
close(LOGFILE);

# Permissions are correct, -w is true
# &errormessage is not invoked
# If I use the literal value for $this_directory it works

Steve.





------------------------------

Date: Wed, 31 Jan 2001 12:53:42 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Should this code work?
Message-Id: <3A787B56.5684DC04@stomp.stomp.tokyo>

Steve wrote:
 
> Could someone please help me to understand why 
> the following does not work:

> $this_directory = "$form_data{'selected_directory'}";  # User form
> $path_to_myfile = '/home/path/to/'.$this_directory.'/myfile.txt';
 
> open(LOGFILE, "<$path_to_myfile") || &errormesssage;

(snipped)

> # If I use the literal value for $this_directory it works
 

Clearly there is a problem with setting your path
as indicated by you. Issue a print command to
discover what data $form_data{'selected_directory'}
contains or, does not contain. Very simple debug:

print $form_data{'selected_directory'};


Based on your comment, a problem exists with your
read and parse routine or a problem exists with
your form action data input method.

There is a more efficient way to write your
code for path development. You will notice
in my Method Three, one variable, $this_directory
has been eliminated which would help your
script fun faster and be more memory efficient.


Godzilla!
__

TEST SCRIPT:
____________

#!perl

print "Content-type: text/plain\n\n";

$form_data{selected_directory} = "TEST";


# Method One:

$this_directory = "$form_data{'selected_directory'}";
$path_to_myfile = '/home/path/to/'.$this_directory.'/myfile.txt';

print "Syntax One Test:\n  $path_to_myfile";


# Method Two:

$this_directory = "$form_data{'selected_directory'}";
$path_to_myfile = "/home/path/to/$this_directory/myfile.txt";

print "\n\nSyntax Two Test:\n  $path_to_myfile";


# Method Three:

$path_to_myfile = "/home/path/to/$form_data{selected_directory}/myfile.txt";

print "\n\nSyntax Three Test:\n  $path_to_myfile";


exit;



PRINTED RESULTS:
________________

Syntax One Test:
  /home/path/to/TEST/myfile.txt

Syntax Two Test:
  /home/path/to/TEST/myfile.txt

Syntax Three Test:
  /home/path/to/TEST/myfile.txt


------------------------------

Date: Wed, 31 Jan 2001 21:38:33 GMT
From: pawsindoors@hotmail.com (Steve)
Subject: Re: Should this code work?
Message-Id: <3a787f38.42047541@news.freeserve.net>

On Wed, 31 Jan 2001 12:53:42 -0800, "Godzilla!"
<godzilla@stomp.stomp.tokyo> wrote:

>Steve wrote:
> 
>> $this_directory = "$form_data{'selected_directory'}";  # User form
>> $path_to_myfile = '/home/path/to/'.$this_directory.'/myfile.txt';
<snipped>
>Clearly there is a problem with setting your path
>as indicated by you. Issue a print command to
>discover what data $form_data{'selected_directory'}
>contains or, does not contain. Very simple debug:
>
>print $form_data{'selected_directory'};
>

print $form_data{'selected_directory'};
gives the correct path:    /home/path/to/target_directory/myfile.txt 

and as I said, using the literal path in place of 
$path_to_myfile = '/home/path/to/'.$this_directory.'/myfile.txt';
does produce a result. In any case, '$path_to_myfile' does open the
file for reading.

if (-w $path_to_myfile)  is true. 

>Based on your comment, a problem exists with your
>read and parse routine 

okay this is sounding likely I will look at this.

>or a problem exists with
>your form action data input method.

>
>There is a more efficient way to write your
>code for path development. You will notice
>in my Method Three, one variable, $this_directory
>has been eliminated which would help your
>script fun faster and be more memory efficient.
>
>
>Godzilla!
>__
>
>TEST SCRIPT:
>____________
>
>#!perl
>
>print "Content-type: text/plain\n\n";
>
>$form_data{selected_directory} = "TEST";
>
>
># Method One:
>
>$this_directory = "$form_data{'selected_directory'}";
>$path_to_myfile = '/home/path/to/'.$this_directory.'/myfile.txt';
>
>print "Syntax One Test:\n  $path_to_myfile";
>
>
># Method Two:
>
>$this_directory = "$form_data{'selected_directory'}";
>$path_to_myfile = "/home/path/to/$this_directory/myfile.txt";
>
>print "\n\nSyntax Two Test:\n  $path_to_myfile";
>
>
># Method Three:
>
>$path_to_myfile = "/home/path/to/$form_data{selected_directory}/myfile.txt";
>
>print "\n\nSyntax Three Test:\n  $path_to_myfile";
>
>
>exit;
>
>
>
>PRINTED RESULTS:
>________________
>
>Syntax One Test:
>  /home/path/to/TEST/myfile.txt
>
>Syntax Two Test:
>  /home/path/to/TEST/myfile.txt
>
>Syntax Three Test:
>  /home/path/to/TEST/myfile.txt

Thanks

Steve.



------------------------------

Date: Wed, 31 Jan 2001 21:49:50 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Should this code work?
Message-Id: <slrn97h23s.9u0.tjla@thislove.dyndns.org>

I was shocked! How could Steve <pawsindoors@hotmail.com>
say such a terrible thing:
>Could someone please help me to understand why the following does not
>work:

Well you don't say what is actually supposed to do.

>$this_directory = "$form_data{'selected_directory'}";  # User form 

Useless stringification.

>$path_to_myfile = '/home/path/to/'.$this_directory.'/myfile.txt';
>
>open(LOGFILE, "<$path_to_myfile") || &errormesssage;
>    flock(LOGFILE, 2);
>       @catalog = <LOGFILE>;  # Reads the file okay
>    flock(LOGFILE, 8);
>close(LOGFILE);

You shouldn't use plain numbers for flock. Better to do:

use Fcntl ':flock';

flock LOGFILE, LOCK_EX;

Also you have a horrible race condition. What happens if another process
attempts to update the file in between this one reading from the file
and then writing to it. You need to hold the lock for the whole
operation. You should probably open the file in update mode '+<', get a
lock, read it all in, truncate the file and then write the new data. You
might want to read the information in:

perldoc -f flock
perldoc -q lock

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
It's fabulous! We haven't seen anything like it in the last half an hour!
-Macy's


------------------------------

Date: Wed, 31 Jan 2001 15:01:18 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Should this code work?
Message-Id: <3A78993E.E4A64245@stomp.stomp.tokyo>

Steve wrote:
 
> Godzilla!" wrote:
> >Steve wrote:

> > > $this_directory = "$form_data{'selected_directory'}";  # User form
> > > $path_to_myfile = '/home/path/to/'.$this_directory.'/myfile.txt';

> (snipped)

> > Clearly there is a problem with setting your path
> > as indicated by you. Issue a print command to
> > discover what data $form_data{'selected_directory'}
> > contains or, does not contain. Very simple debug:

> > print $form_data{'selected_directory'};

> print $form_data{'selected_directory'};
> gives the correct path:    /home/path/to/target_directory/myfile.txt

No, it does not. $form_data{selected_directory} does not
contain this data you cite. Your variable contains or
does not contain data. However, what you show is
generated by your script. Print your variable
and confirm it holds correct data. This would
take only a few minutes and perhaps save you
hours of effort.

 
> and as I said, using the literal path in place of
> $path_to_myfile = '/home/path/to/'.$this_directory.'/myfile.txt';
> does produce a result. In any case, '$path_to_myfile' does open the
> file for reading.

Your current comments directly contradict your previous
comments. These current comments are also self-contradictory.
You say a literal string works and, you say a variable string
works, so there is no problem. Previously, you stated your
variable string does not work. Now you say it does. This
is rather self-contradictory.
 
> >Based on your comment, a problem exists with your
> >read and parse routine
 
> okay this is sounding likely I will look at this.

Then you have not tested your $form_data{'selected_directory'}
variable and, within this article, you say you have. This
makes two major contradictions in your statements.

 
Making these types of argumentative contradictory
statements lessens any likelihood I will assist
you further.


Godzilla!


------------------------------

Date: Wed, 31 Jan 2001 19:26:06 GMT
From: "D'oh" <aa533@chebucto.ns.ca>
Subject: simple split question....
Message-Id: <iFZd6.180990$f36.7184386@news20.bellglobal.com>

Is it possible to split on a specific instance of a matched pattern?    More
often than not I only need the string to be split on the second instance.
It's not a big deal to just have it split on my pattern and then reassemble
the string, but I thought if there was a way to tell it to split on the
second match I would take advantage of it.


Thanks,


Greg




------------------------------

Date: 31 Jan 2001 19:39:17 +0000
From: nobull@mail.com
Subject: Re: simple split question....
Message-Id: <u9bssno6je.fsf@wcl-l.bham.ac.uk>

"D'oh" <aa533@chebucto.ns.ca> writes:

> Is it possible to split on a specific instance of a matched pattern?

Not directly.

> It's not a big deal to just have it split on my pattern and then reassemble
> the string, but I thought if there was a way to tell it to split on the
> second match I would take advantage of it.

I doubt you'll find a better solution.  You may, possibly, find a
faster solution but it would not be as readable.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


------------------------------

Date: 31 Jan 2001 23:27:54 +0100
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: simple split question....
Message-Id: <snlze4r9.fsf@macforce.sumus.dk>

nobull@mail.com writes:

> "D'oh" <aa533@chebucto.ns.ca> writes:
> 
> > Is it possible to split on a specific instance of a matched pattern?
> 
> Not directly.

How about (untested)

  ( $part1, $part2 ) = $string =~ /^(.*?some_pattern.*?)some_pattern(.*)$/;

If I undertand the OP correctly.

Parameterizing this and making it a sub is left as an exercise.

> I doubt you'll find a better solution.  You may, possibly, find a
> faster solution but it would not be as readable.

I think the above is pretty straight forward, no?

-- 
Jakob Schmidt
http://aut.dk/orqwood
etc.


------------------------------

Date: Wed, 31 Jan 2001 21:13:06 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Sorting in NT like in Unix
Message-Id: <slrn97gvv2.9u0.tjla@thislove.dyndns.org>

I was shocked! How could donz30@my-deja.com <donz30@my-deja.com>
say such a terrible thing:
>Unfortunately i'm not a develloper, i'm just trying to modify an
>existent script.

"I'm not a doctor, I'm just attempting heart surgery".

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
It doesn't sound quite as appealing when you think of it as "sticking
your noseinto plant genitalia and inhaling," does it?


------------------------------

Date: Thu, 1 Feb 2001 09:24:49 +1100
From: "Chris W" <chrisw@dynamite.com.au>
Subject: Re: Sorting in NT like in Unix
Message-Id: <ei0e6.12$zt5.1563@news0.optus.net.au>

<donz30@my-deja.com> wrote in message news:958ksh$t5q$1@nnrp1.deja.com...
> Could somebody help me?
> I need to find a way to sort in NT like in Unix environment.
> The command line that i need to let work in NT is:
> sort -k 4

There is nothing in the standard NT environment that has the equivalent
functionality.

You could try an find an NT port of GNU sort (textutils package. Try
http://atnetsend.ne.mediaone.net/programming.html) on the web or you could
handle the sort in a Perl script - but you'll have to write this yourself.




------------------------------

Date: 31 Jan 2001 20:52:04 GMT
From: The WebDragon <nospam@nospam.com>
Subject: strange behaviour of Net::SMTP
Message-Id: <959ttk$f4v$0@216.155.33.15>

using the following program as a test

#!perl -w
use strict;
use Net::SMTP;

my($smtp, $email, @emails, $subject, $message);

   #hidden true addrs so spam collectors won't find 
$smtp    = Net::SMTP->new('mail.myhost.com') or die "$!";
$email   = 'myfirst@address.com';
@emails  = 'mysecond@address.com';
$subject = "Subject: testing Perl SMTP access";
$message = <<'EOM';
 
Perl sent this message.  Nifty, eh? :-)

Just another Perl Hacker hard at work. =]

EOM

$smtp->mail($email)       or warn('failure');
$smtp->to(@emails)        or warn('failure');
$smtp->data()             or warn('failure');
$smtp->datasend($subject) or warn('failure');
$smtp->datasend($message) or warn('failure');
$smtp->dataend()          or warn('failure');
$smtp->quit()             or warn('failure');

exit 0;

the e-mail gets through ok, but in the headers is the following: 

X-Fix: NTMail fixed non RFC822 compliant EMail message

looking in Net::SMTP I see reference to RFC821 not 822.. 

Is there something *I'M* doing wrong here? It seems pretty 
straightforward...

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


------------------------------

Date: Wed, 31 Jan 2001 21:38:42 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: Re: strange behaviour of Net::SMTP
Message-Id: <95a0l1$4en$1@nnrp1.deja.com>

In article <959ttk$f4v$0@216.155.33.15>,
  The WebDragon <nospam@nospam.com> wrote:
> using the following program as a test
>
> #!perl -w
> use strict;
> use Net::SMTP;
>

RFC821 defines the "simple mail transfer protocol" (implemented in
Net::SMTP).  It deals with connecting to an mta (message transfer
agent) to deliver messages.  RFC 822 defines the actual 'message
format' (for arpa internet text messages).  As such there is no
relationship between rfc821 and 822.

There are modules to create nice rfc822
compliant messages, but usually the following
headers are enough if all you are doing is
sending simple emails.  Message body is best
kept to short lines, and plainest ascii.
Otherwise mime extensions have to be added
and the message encoded as Quoted=Printable,
etc (there are modules for all those).


Message-ID: <someweirdstring@host.yourdomain>
From: "realname" <username@hostname>
To: "real name" <username@hostname>
Date: 31 Jan 2001 00:00:00 GMT
Subject: ..some subject

This Message body is separated from
headers by a blank line


B


Sent via Deja.com
http://www.deja.com/


------------------------------

Date: Wed, 31 Jan 2001 19:31:27 -0000
From: "Géry" <ducateg@info.bt.co.uk>
Subject: trap die
Message-Id: <959pbm$l91$1@pheidippides.axion.bt.co.uk>

I have a module that is meant to trap die, it looks like this:

#!c:\perl\bin\perl

package Index::Error;

use Exporter;

@ISA = qw(Exporter);
@EXPORT = qw(display_error);

use CGI ( -unique_header );
use CGI::Carp qw(fatalsToBrowser);
use strict;


BEGIN
{
  sub carp_error
  {
    my $error_message = shift;
    my $q = new CGI;
    my $discard_this = $q -> ("text/html");
  display_error($q, $error_message);
  }
  CGI::Carp::set_message(\&carp_error);
}


sub display_error
{
  my ($q, $error_message)=@_;
  print $q->header("text/html"),
  print $q->p("Error msg $error_message"),
  print $q->end_html;
  exit;
}

1;

I got that code of the CGI programming with Perl book.

I have another module that opens some files, thus the picture:

CGI perl script ---------> module to open file ----------> module to trap
die.

The CGI perl script calls a module that should open some files, read data
and return its business to the CGI bit. In case a die is call, I want to
trap it and display a house message.

This code sits in the "module to open file":

I have tried
    open (INV, "< $inverted_file") or die "Cannot open the inverted file:
$!";
which return a blank page

and
    open (INV, "< $inverted_file") or display_error($q, "Cannot open the
inverted file");
which has a very odd behaviour. It seems to compile upside down, thus, the
html header is only cast to the browser last, which is a behaviour that does
not seem to suit the browsers...


Any help, shared experience more than welcome
--
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Géry Ducatel
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<






------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 186
**************************************


home help back first fref pref prev next nref lref last post