[23868] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6071 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 3 11:05:48 2004

Date: Tue, 3 Feb 2004 08:05:07 -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           Tue, 3 Feb 2004     Volume: 10 Number: 6071

Today's topics:
    Re: Capture stderr stdout using system call with commas <seawolf@attglobal.net>
        CGI syntax error not behaving as I expected but... <mmosher@storm.ca>
    Re: CGI syntax error not behaving as I expected but... <usenet@morrow.me.uk>
    Re: CGI syntax error not behaving as I expected but... <ittyspam@yahoo.com>
    Re: Checking to see if a paticular file exists <jurgenex@hotmail.com>
        Cold Fusion/HTML Text Box Printing Help - Thanks in adv (Boyd Myers)
    Re: Cold Fusion/HTML Text Box Printing Help - Thanks in <noreply@gunnar.cc>
    Re: difficult substitution patterns (Peter)
    Re: Embedded Perl sprintf (symbol?) problem. <kalinaubears@iinet.net.au>
        File handlings <glodalec@yahoo.com>
    Re: File handlings <usenet@morrow.me.uk>
    Re: network card <javier@t-online.de>
    Re: open a ascii file and rotate the content 90 deg... <mgjv@tradingpost.com.au>
        problem with large hash vanishing (Jack)
    Re: problem with large hash vanishing <noreply@gunnar.cc>
    Re: problem with large hash vanishing <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: problem with large hash vanishing <dwall@fastmail.fm>
    Re: Two regular expression questions <noemail@noemail4u.com>
        Use of uninitialized value in concatenation (.) or stri <simbaplt.REMOVE.NO.SPAM.PLEASE@yahoo.no.spam.please.com>
    Re: Use of uninitialized value in concatenation (.) or  <noreply@gunnar.cc>
    Re: When to "use strict" when teaching? (Mark Jason Dominus)
    Re: When to "use strict" when teaching? <spamtrap@dot-app.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 03 Feb 2004 15:41:35 GMT
From: Leslie Hazelton <seawolf@attglobal.net>
Subject: Re: Capture stderr stdout using system call with commas?
Message-Id: <PiPTb.167926$6y6.3283001@bgtnsc05-news.ops.worldnet.att.net>

This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig8FF4C510CDE5BF60C1A80A62
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Marv wrote:
> Hello,
> 
> I've got an issue that I can't seem to figure out.
> 
> I'm trying to run some mount and rsync commands from inside a perl
> script. 
> 
> I've figured out from other postings that you have to use a system
> call and seperate all the command line options with quotes and commas.
> I'm not sure why this is, but I can never get the commands to work if
> I enclose them with backticks? Can anybody explain this?
> 
> Anyway, if the commands could be enclosed in backticks I would have my
> problem solved, but since I have to use system (), I can't seem to
> figure out how to capture this data either to a variable or a file.
> I've tried using '2>&1 tmp.errors' but this doesn't work either
> because of the commas. Here is a sample of what I'm doing:
> 
>                 system (
>                         "mount",
>                         "-r",
>                         "-t",
>                         "smbfs",
> 
> "-o","username=$adminuser,password=$adminpass",
>                         "//$ip/$ashare",
>                         "/share/$nbname/$ashare",
>                         "2>&1 tmp.errors"
>                 );
> 
> This method doesn't work because it takes the '2>&1 tmp.errors' as
> another option of mount and bombs out. If I include it at the end of
> '/share/$nbname/$ashare' then it takes as part of the name of the
> mount point and bombs out.
> 
> Can anybody help me capture this info? Or show me how this can be down
> with backticks.
> 
> Thanks.
> Marv
> 

I have several perl scripts that run as cron jobs and I want to capture 
all the output into a log file for later review.  I use a two stage 
approach to do this. The cron job is a shell script that runs the perl 
program.

This is a snip of the perl portion. The main concept came from the Perl 
Cookbook, O'Reilly, ISBN 1-56592-243-3.
------------- snippet -------------
  my @archiveDir = ("/mnt/Archives", "/tmp", "/root");

  foreach my $var ( @archiveDir) {
    my $args = "$var/\*$cleanDate\*";

    print "Removing files matching [$args]\n";
    print "\tRunning [rm -f $args]\n";

    open (MyCmd, "rm \-f $args |") or die "Can't run program: $!\n";
    while (<MyCmd>) {
          my $output .= $_;
          print $output;
          }
    close (MyCmd);
    }
-------------- end snippet ----------

The shell script which executes the perl program clean-archive is as 
follows.

#!/bin/bash
#
runDate=`date +%F`
logFile=/root/clean-archive-$runDate.log
/root/clean-archive  > $logFile 2>&1


While this may not be the most elegant approach I find it works well for 
me.  In any case, it's another varient for your consideration.


-- 
Les Hazelton
Registered Linux user # 272996

--------------enig8FF4C510CDE5BF60C1A80A62
Content-Type: application/pgp-signature

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAH8EvoMRiAeiXZ8MRAsPpAJ4xUM4zxQwNfdonuBX6khPipCvRHQCfQeYX
g7mC/66tlJkRXOgLj4c98P0=
=k+6h
-----END PGP SIGNATURE-----

--------------enig8FF4C510CDE5BF60C1A80A62--


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

Date: Tue, 03 Feb 2004 10:06:12 -0500
From: mmosher <mmosher@storm.ca>
Subject: CGI syntax error not behaving as I expected but...
Message-Id: <bvoddm$mqu$1@news.storm.ca>

 ... doing exactly what its supposed to do.

I wrote a perl script to allow me to look at portions of the log that is 
kept for people searching. It was written some time ago and seemed to 
work perfectly. It was not until last week that I noticed that after 
12pm the time would jump back an hour and stay that way until 12am. I 
suspected a bug but doubled check incase of some weird virus or something.

Of course it was a bug:

  if (substr($date_time_raw[$loop],8,2)<12)           {##do something}
  elsif (substr($date_time_raw[$loop],8,2)=12)       {##do something}
  
else                                                                      
{##do something}

Of course the error is in the elsif statement it should be ==12 not =12. 
So of course it works in the am the pm messes up.

My question is this: I thought a syntax error of this type would not run 
and that I would get an error with no output? Or is this type of error 
considered a warning?

I am fairly inexperienced in perl and usually have to write stuff as "we 
need this up tommorrow. Figure it out quick" kinda of situation which is 
not a good way to actually learn and understand. I also do most of perl 
work in the morning and it did not occur to change the clock and test 
different hours. Lesson learned.

Thank you.



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

Date: Tue, 3 Feb 2004 15:24:46 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: CGI syntax error not behaving as I expected but...
Message-Id: <bvoefu$t31$2@wisteria.csv.warwick.ac.uk>


mmosher <mmosher@storm.ca> wrote:
> Of course it was a bug:
> 
>   if (substr($date_time_raw[$loop],8,2)<12)           {##do something}
>   elsif (substr($date_time_raw[$loop],8,2)=12)       {##do something}
>   
> else                                                                      
> {##do something}
> 
> My question is this: I thought a syntax error of this type would not run 
> and that I would get an error with no output? Or is this type of error 
> considered a warning?

Using substr as an lvalue like this is perfectly valid Perl. Read
perldoc -f substr again.

perl -le'my $x = "abc"; substr($x, 1, 1) = "XXX"; print $x'

Ben

-- 
   If you put all the prophets,   |   You'd have so much more reason
   Mystics and saints             |   Than ever was born
   In one room together,          |   Out of all of the conflicts of time.
ben@morrow.me.uk |----------------+---------------| The Levellers, 'Believers'


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

Date: Tue, 3 Feb 2004 10:28:07 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: CGI syntax error not behaving as I expected but...
Message-Id: <20040203102540.M483@dishwasher.cs.rpi.edu>

On Tue, 3 Feb 2004, mmosher wrote:

> Of course it was a bug:
>
>   if (substr($date_time_raw[$loop],8,2)<12)           {##do something}
>   elsif (substr($date_time_raw[$loop],8,2)=12)       {##do something}
>
> else
> {##do something}
>
> Of course the error is in the elsif statement it should be ==12 not =12.
> So of course it works in the am the pm messes up.
>
> My question is this: I thought a syntax error of this type would not run
> and that I would get an error with no output? Or is this type of error
> considered a warning?
>

That's not a syntax error.  Assigning a value to a substring is a
perfectly legal operation.  It's just not what you wanted to do.  That
line says "find the 2 character substring from the variable
$date_time_raw[$loop] starting at position 8, and replace it with the
string "12".  There's no syntax error there at all.

Paul Lalli



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

Date: Tue, 03 Feb 2004 15:06:32 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Checking to see if a paticular file exists
Message-Id: <YNOTb.39$EH5.7@nwrddc01.gnilink.net>

vijay wrote:
>   I'm trying to check to see if a paticular file exist on the machine,

See "perldoc -f -e"

> i'm unable to check for files insides directories which have space in
> between their names, If i run the script from the command prompt they
> seem to run fine,

Then chances are your problem is _not_ a Perl problem. Please see
"perldoc -q 500"

> but when i try to open the script on a browser,

How do you "open a script on a browser"?

> it
> is not able to even open the directory, i get a Invalid Argument
> Error,
> This does not happen for directories which do not have a space
> in their name.Any help is greatly appreciated

Well, quite impoossible to do without seeing your code (or actually a
minimal example that exposes the problem).

jue




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

Date: Tue,  3 Feb 2004 08:32:26 CST
From: rockytoptilidie@hotmail.com (Boyd Myers)
Subject: Cold Fusion/HTML Text Box Printing Help - Thanks in advance
Message-Id: <5237bea4.0402030630.5a049795@posting.google.com>

The current print feature for my program will only print what is
viewable in the text box.  If the text exceeds the size of the display
box, additional characters are not printed.  I'm using CF Studio 5.0
(is probably irrelevant, but anyway).

When using the Internet Explorer print button for this form, how can I
print the entire area of the text box without it being chopped off?

Any help on this is appreciated - I'd prefer to do it this way other
than a "Click Here For Printable Version" button!!!

Boyd


-- 
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.

HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html



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

Date: Tue,  3 Feb 2004 09:03:20 CST
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Cold Fusion/HTML Text Box Printing Help - Thanks in advance
Message-Id: <bvod75$uoghs$1@ID-184292.news.uni-berlin.de>

Boyd Myers wrote:
> When using the Internet Explorer print button for this form, how
> can I print the entire area of the text box without it being
> chopped off?

Maybe you should ask Microsoft? But, even if I'm not sure, I have a
feeling that all browsers work that way.

Anyway, this is not a Perl question, I doubt it's in the CGI category,
and I don't know about TECHWR-L.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


-- 
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content.

HOW TO POST to comp.infosystems.www.authoring.cgi:
http://www.thinkspot.net/ciwac/howtopost.html



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

Date: 3 Feb 2004 07:14:33 -0800
From: peter_holmes2003@yahoo.com (Peter)
Subject: Re: difficult substitution patterns
Message-Id: <9e41635d.0402030714.413147c9@posting.google.com>

Thanks John and Tad for answering my questions.

"John W. Kennedy" <jwkenne@attglobal.net> wrote in message news:<ar_Sb.18963$gw3.9065623@news4.srv.hcvlny.cv.net>...
> Peter wrote:
> 
> > I am relative newbie to perl . i am reading programming perl to learn
> > perl. In the chanper on pattern matching I came across the following
> > sustitutions that I can't understand completely. It would be great if
> > someone could explain these.
> > 
> > Thanks in advance
> > 
> > a)
> > #put commas in the right place in an integer
> > 
> > 1 while s/(\d) (\d\d\d) (?!\d)/$1,$2; 
> > # what does this mean (?!\d) and what purpose does it serve
> 
> The correct form of the line is:
> 1 while s/(\d)(\d\d\d)(?!\d)/$1,$2/;
> 
> The (?!\d) is what is known as a zero-width assertion.  It means that 
> after the (\d) and the (\d\d\d) there is _not_ another \d.  That it is a 
> "zero-width assertion" means that the thing it matches doesn't count as 
> part of the match; it's just checked.
> 
> Let's say that we are processing 12345678.
> 
> We try the match.  The first thing that works is the '5' (which matches 
> '(\d)'), the '678' (which matches '(\d\d\d)') and the end, which is not 
> a \d.
> 
> That changes $_ to '12345,678'.  Because the s/.../.../ worked, we 
> repeat the while.  This time, the first thing that works is the '2' 
> (which matches '(\d)'), the '345' (which matches '(\d\d\d)'), and the 
> ',', which is not a \d.
> 
> That changes $_ to '12,345,678.  The comma after the '5' is not changed 
> because '(?!\d)' is a zero-width assertion, and therefore doesn't count 
> as part of the match, and therefore is not part of what is replaced. 
> Because the s/.../.../ worked, we repeat the match a third time, but 
> there isn't another match, and so the while terminates.
> 
> > b)
> > #remove (nested (even deeply nested (like this))) remarks
> > 
> > 1 while s/\([^()]*\)//g; 
> > # why escape the first ( and second ), what about the ( or ) in
> > between
> 
> The escapes are there to indicate that they are literal parentheses to 
> be scanned for, not grouping operators in regular-expression language.
> 
> The escapes are not within the [] because parentheses have no meaning 
> within [], and are therefore automatically taken as literal.
> 
> To expand, the regular expression means this:
> 
> Match on a (, followed by zero or more characters that are not ( or ), 
> followed by a ).
> 
> The first time, we get "remove (nested (even deeply nested )) remarks".
> The second time, we get "remove (nested ) remarks".
> The third time, we get "remove  remarks".
> The fourth time, there is no match, and the while terminates.


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

Date: Wed, 04 Feb 2004 00:05:05 +1100
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: Embedded Perl sprintf (symbol?) problem.
Message-Id: <401f9d76$0$1734$5a62ac22@freenews.iinet.net.au>

gnari wrote:

> Still, the idea is valid. the OP should try to make a minimal program w/
> embedded perl, and see if the problem persists.

I'd stop short of saying that it's mandatory to provide some compilable 
demonstration code - but I, for one, am certainly *not* going to think 
about the problem if I have to create test code from scratch. I imagine 
that others share the same attitude.

Otoh, if there was some code supplied I would certainly look at it, and 
play with it, and try to determine the cause of the problem .... not to 
say that I'd succeed, of course :-)

It's just that it's simply in the best interests of the OP to follow the 
posting guidelines and supply such code. That's all I was trying to get 
at :-)

Cheers,
Rob


-- 
To reply by email u have to take out the u in kalinaubears.



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

Date: Tue, 3 Feb 2004 15:13:15 +0100
From: Glodalec <glodalec@yahoo.com>
Subject: File handlings
Message-Id: <MPG.1a89cad4386490ae98974a@news.siol.net>

Hi !

My B program is a simple script, which reads a string from STDIN, 
converts it to uppercase and prints it to STDOUT.

B.pl
#!/bin/perl 
use strict ;
my $string=<STDIN>;
print STDOUT uc $string,"\n" ;

Now, I have A program, which listens on a TCP socket. Whenever string 
come over socket, it should be put on STDIN buffer (yes, STDIN), forking 
a new child, redirecting the parent SOCKET to child's STDOUT and exec 
B.pl. (The same way Apache & CGI modules work). I was trying to use 
select() but no luck.

A.pl
#!/bin/perl
use strict ;
 ...
SOCKET CREATION, LISTENING, GETTING LINE FROM A SOCKET INTO $LINE
 ...

TCP settings....
 ......
   if (my $pid=fork)
   {
      waitpid($pid,0);   # Ok, here is parent
   } else
   {
      my $string="This must be put in STDIN buffer" ; << Don't know how
      my $old=select(SOCKET) ;  << This is not working
      exec("A.pl");       # and child
      select $oldstdout ;
   }

Any help would be appreciated


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

Date: Tue, 3 Feb 2004 15:21:33 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: File handlings
Message-Id: <bvoe9t$t31$1@wisteria.csv.warwick.ac.uk>


Glodalec <glodalec@yahoo.com> wrote:
> Now, I have A program, which listens on a TCP socket. Whenever string 
> come over socket, it should be put on STDIN buffer (yes, STDIN), forking 
> a new child, redirecting the parent SOCKET to child's STDOUT and exec 
> B.pl. (The same way Apache & CGI modules work). I was trying to use 
> select() but no luck.

No, that's not how filehandles work at all. You can't push stuff back
onto them: if you want to pass stuff to your child you have to use a
pipe. 

> A.pl
> #!/bin/perl
> use strict ;
> ...
> SOCKET CREATION, LISTENING, GETTING LINE FROM A SOCKET INTO $LINE
> ...
> 
> TCP settings....
> ......
>    if (my $pid=fork)

fork can fail, in which case it returns undef.

>    {
>       waitpid($pid,0);   # Ok, here is parent
>    } else
>    {
>       my $string="This must be put in STDIN buffer" ; << Don't know how
>       my $old=select(SOCKET) ;  << This is not working
>       exec("A.pl");       # and child
>       select $oldstdout ;
>    }
> 
> Any help would be appreciated

my $pid = open my $TOCHILD, '|-', 'A.pl'
    or die "fork failed: $!";

print $TOCHILD "The child will read this on its STDIN";

See perldoc -f open.

Ben

-- 
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * ben@morrow.me.uk


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

Date: Tue, 03 Feb 2004 14:18:39 +0100
From: Xaver Biton <javier@t-online.de>
Subject: Re: network card
Message-Id: <bvo71b$j1a$07$1@news.t-online.com>

Joe Smith wrote:

> Are you trying to set up a network connection that will use a dial-up
> ISP of your own choosing without the user being aware of it?
> 
> That's a technique used by porn sites to force unwitting users to
> rack up expensive long-distance telephone charges.

Dear Mr. Smith,

you don't have to thing, that everyone that want to automate a network 
connection, he want to do it to swindle the people. I want to do it for 
a ISP. the script will be incorporate in the istallation Programm.

I'm ready to collaborate making a perl programm to watch out the 
connections, and protect the internet user from such program, and make 
it open source.

Regards.

Xaver Biton



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

Date: Tue, 3 Feb 2004 22:40:33 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: open a ascii file and rotate the content 90 deg...
Message-Id: <slrnc1v25h.ts4.mgjv@martien.heliotrope.home>

On Mon, 02 Feb 2004 12:36:47 +0800,
	lyoute <lyoute@softhome.net> wrote:
> 
> 
> i got a set of files all looks like: (with fixed dimension 8x8)
> .X..XO..
> X...XO..
> OXX.XO..
> OOOXXO..
> ...OO.O.
> ..O.....
> ........
> ........
> 
> how can i produce output with 90 deg rotated:
> .XOO....
> X.XO....
> ..XO.O..
> ...XO...
> XXXXO...
> OOOO....
> ....O...
> ........

Maybe something like:

undef $/;
$_ = <DATA>;
while (my @l = m/^(.)/mg)
{
    print @l, "\n";
    s/^.//mg;
}

__DATA__
 .X..XO..
X...XO..
OXX.XO..
OOOXXO..
 ...OO.O.
 ..O.....
 ........
 ........


Martien
-- 
                        | 
Martien Verbruggen      | +++ Out of Cheese Error +++ Reinstall
                        | Universe and Reboot +++
                        | 



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

Date: 3 Feb 2004 04:54:41 -0800
From: j.cawkwell@open.ac.uk (Jack)
Subject: problem with large hash vanishing
Message-Id: <6ef7107a.0402030454.12680b92@posting.google.com>

Hi,

I have a perl v5.6.0 program, which reads a
configuration file into a hash of hashes.
The rest of the program does a fetch from
an oracle database, and uses the configuration
hash to do processing. After a number of
successful loops the configuration hash
vanishes, becoming undefined. I have used
perl -d with the W command to watch the
config hash change, but it does not get zapped
to undefined in the debugger.

Can anyone suggest what might be going wrong,
and what further debugging I could try?

The program is a bit big to post, and it belongs
to my employer.

Thanks, Jack


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

Date: Tue, 03 Feb 2004 13:59:11 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: problem with large hash vanishing
Message-Id: <bvo5rj$u9e54$1@ID-184292.news.uni-berlin.de>

Jack wrote:
> The program ... belongs to my employer.

Then I suggest that you ask your employer for help.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 3 Feb 2004 14:12:07 +0100
From: Bernard El-Hagin <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: problem with large hash vanishing
Message-Id: <slrnc1v7bl.id.bernard.el-haginDODGE_THIS@gdndev25.lido-tech>

On 2004-02-03, Jack <j.cawkwell@open.ac.uk> wrote:
> Hi,
>
> I have a perl v5.6.0 program, which reads a
> configuration file into a hash of hashes.
> The rest of the program does a fetch from
> an oracle database, and uses the configuration
> hash to do processing. After a number of
> successful loops the configuration hash
> vanishes, becoming undefined. I have used
> perl -d with the W command to watch the
> config hash change, but it does not get zapped
> to undefined in the debugger.
>
> Can anyone suggest what might be going wrong,


Yes. You should have $x + 1 instead of $x - 1 in line 982.


> and what further debugging I could try?
>
> The program is a bit big to post, and it belongs
> to my employer.


So why are you bugging us, then? Did you just have all these feelings
bottled up inside you and just wanted to share them?

-- 
Cheers,
Bernard


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

Date: Tue, 03 Feb 2004 15:53:40 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: problem with large hash vanishing
Message-Id: <Xns94846ED3568F4dkwwashere@216.168.3.30>

Jack <j.cawkwell@open.ac.uk> wrote:

> I have a perl v5.6.0 program, which reads a
> configuration file into a hash of hashes.

Depending on the format of the config file, you may be able to use a CPAN 
module to do this (if you're not already doing so).

> The rest of the program does a fetch from
> an oracle database, and uses the configuration
> hash to do processing. After a number of
> successful loops the configuration hash
> vanishes, becoming undefined. I have used
> perl -d with the W command to watch the
> config hash change, but it does not get zapped
> to undefined in the debugger.
> 
> Can anyone suggest what might be going wrong,

My crystal ball says you have a bug on line 537 that is overwriting your 
hash.

> and what further debugging I could try?

No, because you didn't post any code.

> The program is a bit big to post, and it belongs
> to my employer.

I doubt we'd want to see the entire program anyway. 

Standard advice: Break it down into a short, preferably self-contained test 
case that exhibits the problem. The process of doing so often reveals the 
problem (it usually works for me), and if not you have a snippet of code 
you can post for us to look at.

-- 
David Wall


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

Date: Tue, 03 Feb 2004 12:17:18 GMT
From: Dang Griffith <noemail@noemail4u.com>
Subject: Re: Two regular expression questions
Message-Id: <73f504b601faa503abc460a1aad184db@news.teranews.com>

On Mon, 2 Feb 2004 12:56:41 -0500, Jeff 'japhy' Pinyan
<pinyaj@rpi.edu> wrote:

>On Mon, 2 Feb 2004, Dang Griffith wrote:
>
>>1. Is there a more appropriate newsgroup to post questions regarding
>>regular expressions?  I know many languages now support them, but Perl
>>is generally considered the de facto standard.  (Yes?)
>
>This is the place to ask questions about Perl's regexes.
>
>>2. Are there plans to add syntax to support matched-nesting, for
>>things such as balanced parenthesis, angle-brackets, and quote marks?
>>It's my understanding that there currently is not support for this,
>>which is why you can't parse xhtml-like text with simply a regular
>>expression.  I.e., you need to go to the next level and write a parser
>>to maintain the state of the nesting.
>
>You can match nested things with Perl's regexes, because Perl's regexes
>aren't... well... regular.  You can execute arbitary code.  You can
>dynamically generate the regex as it's being matched.
Thanks to Jeff and Walter.  You both confirmed what I thought to be
the case.  I.e., regular expressions cannot support nested matching,
but that additional programming can be created to support it.
    --dang rpi '87


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

Date: Tue, 3 Feb 2004 03:05:28 -0800
From: "S" <simbaplt.REMOVE.NO.SPAM.PLEASE@yahoo.no.spam.please.com>
Subject: Use of uninitialized value in concatenation (.) or string
Message-Id: <ytadncBAXbd_HYLdRVn-vw@comcast.com>

Hi,

In advance sorry for the lengthy email. I'm new at using Perl and I have
never posted here so my goal is to hopefully provide as much information as
neccessary.  I provided:
- a broken test script exhibiting a problem (along with the output)
- a fixed test script no longer exhibiting the problem (along with the
output)
- a quick description of my environment
- a list of what I tried

One could wonder why I'm posting here since I already have 'a fix'.  Well, I
would like to understand why moving this specific line of code fixed the
problem. Specifically, I want to understand why it seems that a 'hash' can
be alternatively 'initialized' or 'uninitialized' in the broken script. It
just does not make sense to me with my limited knowledge.


In my example, assuming that %messages turned out to be a very big hash,
what would be the impact of rebuilding the @sortedmessages array every time
in the loop as I'm doing in the 'fixed' test script? Yes, I know that it
sounds like I want to optimize before I even know how to code. Here again,
it is just for my own 'edification'. Thanks for reading the rest of the mail
and teaching me along.

Note 1: the script is written for learning purpose only, you are welcome to
comment on it also.
Note 2: English is not my native language and I'm trying really hard to be
understood on this forum. :-)


The test script exhibiting a problem:
=========================
use strict;
use warnings;
my %messages;
$messages{"C"}="333";
$messages{"B"}="222";
$messages{"A"}="111";
my @sortedmessages = map { { ($_ => $messages{$_}) } } sort keys %messages;
my $maxi=2;
my $message_element;
my $key = my $value;
foreach my $i (0...$maxi)
{
    foreach $message_element (@sortedmessages)
    {
       ($key, $value) = each %$message_element;
       print ("key is $key and value is $value\n");
    }
}


Output with the broken script:
=====================
key is A and value is 111
key is B and value is 222
key is C and value is 333
Use of uninitialized value in concatenation (.) or string at
D:\test.pl line 16.
Use of uninitialized value in concatenation (.) or string at
D:\test.pl line 16.
key is  and value is
Use of uninitialized value in concatenation (.) or string at
D:\test.pl line 16.
Use of uninitialized value in concatenation (.) or string at
D:\test.pl line 16.
key is  and value is
Use of uninitialized value in concatenation (.) or string at
D:\test.pl line 16.
Use of uninitialized value in concatenation (.) or string at
D:\test.pl line 16.
key is  and value is
key is A and value is 111
key is B and value is 222
key is C and value is 333


The 'fixed' test script no longer exhibiting a problem
=====================================
use strict;
use warnings;
my %messages;
$messages{"C"}="333";
$messages{"B"}="222";
$messages{"A"}="111";
my $maxi=2;
my $message_element;
my $key = my $value;
foreach my $i (0...$maxi)
{
   #line 7 from broken script was moved here and fixed the problem
   my @sortedmessages = map { { ($_ => $messages{$_}) } } sort keys
%messages;
   foreach $message_element (@sortedmessages)
   {
       ($key, $value) = each %$message_element;
       print ("key is $key and value is $value\n");
    }
}

Output with fixed script:
=====================
key is A and value is 111
key is B and value is 222
key is C and value is 333
key is A and value is 111
key is B and value is 222
key is C and value is 333
key is A and value is 111
key is B and value is 222
key is C and value is 333


Current environment:
==============
ActiveState Perl v5.8.0 built for MSWin32-x86-multi-thread (build 806) under
Win2K.

What I tried:
=========
- searched on Google
- looked at the Perl documentation locally available
- ran the script Open_Perl_IDE\PerlIDE.exe ( I don't seem able to reproduce
this problem with that debugger or maybe I don't know how to use it. :-)





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

Date: Tue, 03 Feb 2004 12:53:12 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Use of uninitialized value in concatenation (.) or string
Message-Id: <bvo1vr$u77n5$1@ID-184292.news.uni-berlin.de>

S wrote:
> Specifically, I want to understand why it seems that a 'hash' can 
> be alternatively 'initialized' or 'uninitialized' in the broken
> script.

You have probably not understood how the each() function works. Please
study the documentation for it:

     http://www.perldoc.com/perl5.8.0/pod/func/each.html

If you just skip the redundant use of each() in your "broken" script,
it will work as expected:

         ($key, $value) = %$message_element;

HTH

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 3 Feb 2004 15:44:56 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: When to "use strict" when teaching?
Message-Id: <bvoflo$chh$1@plover.com>

In article <bvlvj6$36g$1@south.jnrs.ja.net>,
Simon Andrews  <simon.andrews@bbsrc.ac.uk> wrote:
>1) When do you think it's best to introduce strictures into the programs 
>people write.


When I do three-day intro classes, I introduce subroutines early in
the afternoon of day 2.  The next section of the class is about 'my'
variables, because there's no use for 'my' variables until your
programs are big enough to need to have subroutines.  The section of
'my' variables discusses 'strict vars', but not either of the other
strictures, which are less useful.

The motivation for all three features is similar.  You want
subroutines for modularity and reusability.  Subroutines that refer to
global variables are neither modular nor reusable, so you need 'my'
variables.  And 'strict vars' helps you remember to declare the
variables.

I don't cover 'strict refs' until the following afternoon, after we've
seen references; then I can discuss the serious and untraceable
problems that can be caused by accidental use of symbolic references.

I never discuss 'strict subs' at all.  It's not worth the time.

I think the philosophy that says that you should always have 'use
strict' at the top of every program from the start of day one is
misguided.  The theory is that you're training people to follow good
programming practices.  But this theory somehow manages to forget that
putting stuff into your program when you don't know what it does is
the very worst of all possible programming practices.

The folks who piss and moan the loudest about cargo-cult programming
practices and Matt's Script Archive and soforth are always the ones
who are proclaiming most loudly that you Must Always Use Strict.  It
seems that what they really want is for people to join *their* cargo cult.

More generally, I have a philosophical problem with commanding people
to do things when they don't understand why.  I don't think people
should be trained to follow instructions without understanding the
policy, and I don't want to participate in doing it.  My job, as a
teacher, is to make people wise and powerful, and saying "just do this
all the time even though you don't know what it's for" is a the way to
make them weak and stupid.



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

Date: Tue, 03 Feb 2004 10:48:11 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: When to "use strict" when teaching?
Message-Id: <Tf-dnXQvCNYmX4LdRVn-tA@adelphia.com>

Brian McCauley wrote:

> From the outset put the shebang line, "use strict" and "use warnings"
> at the top of all your programs.  Mention in passing that use strict
> "disables some feature that are mostly for Perl4 backward
> compatability"

That's a great way to describe what strict does.

I've often wondered whether newbies' reluctance towards strictures is based
on the negative connotations of the word "strict." The word implies a harsh
taskmaster who won't let his students have any fun. So newbies avoid it and
feel like they're getting away with something.

Perhaps something that helped portray strictures in a positive light, like
"use modern" or "more help", would have been a better choice.

sherm--



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

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


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