[22392] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4613 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 24 00:05:55 2003

Date: Sun, 23 Feb 2003 21:05:05 -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           Sun, 23 Feb 2003     Volume: 10 Number: 4613

Today's topics:
    Re: extract string from another string <mbudash@sonic.net>
    Re: extract string from another string <goldbb2@earthlink.net>
    Re: Just wanted to share this technique (and hear some  <goldbb2@earthlink.net>
    Re: Newbie request for script review <bwalton@rochester.rr.com>
    Re: Newbie request for script review <asu1@c-o-r-n-e-l-l.edu>
    Re: Newbie request for script review (Tad McClellan)
    Re: Newbie request for script review <asu1@c-o-r-n-e-l-l.edu>
    Re: Perl & VB without activeperl on Windows?? (Autrijus Tang)
    Re: Problem installing Perl dbd::mysql in Windows XP. P <eleos111@hotmail.com>
        Pushing onto hash of hash of array <daveh@ci.com.au>
    Re: Pushing onto hash of hash of array <tore@aursand.no>
    Re: Pushing onto hash of hash of array <newsfeed2@boog.co.uk>
    Re: Pushing onto hash of hash of array <newsfeed2@boog.co.uk>
    Re: Switch order of sprintf conversions <goldbb2@earthlink.net>
        What the heck is the scope if $/??? <brundlefly76@hotmail.com>
    Re: What the heck is the scope if $/??? <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 24 Feb 2003 02:24:02 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: extract string from another string
Message-Id: <mbudash-0EAFE2.18240323022003@typhoon.sonic.net>

In article <Usenet.pemtljpi@localhost>, piet <pdhze@yahoo.co> wrote:

> $teststring = 'stuff 650 N other stuff'
> another example of string 'stuff stuff stuff stuff 90 N'
> 
> What would I do to extract 650 N and 90 N from the string?
> 
> 650 N is an example: it can be from 111 A to 999 Z
> 90 N is an example: it can be from 10 A to 99 N
> They are not on a specific place in the string.
> 
> I know how to check if they are in the string, but I don't now how to 
> extract them. So I need 650 N and 90 N stored in a variable or an array
> 
> This is what I already have:
> if ($teststring =~ /\d\d\d [a-zA-Z]|\d\d [a-zA-Z]/) {
> print $teststring;
> }
> 
> Thanks for your help
> piet
> 

close:

if ($teststring =~ /(\d{3} [a-z]|\d{2} [a-n])/i) {
  print $1;
}

notice the capturing parens...

hth-


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

Date: Sun, 23 Feb 2003 21:51:50 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: extract string from another string
Message-Id: <3E5988C6.A094F123@earthlink.net>

piet wrote:
[snip]
> This is what I already have:
> if ($teststring =~ /\d\d\d [a-zA-Z]|\d\d [a-zA-Z]/) {
> print $teststring;
> }

   my ($extracted) = $teststring =~ /(\d\d\d? [a-z])/i;

-- 
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print


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

Date: Sun, 23 Feb 2003 18:41:32 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Just wanted to share this technique (and hear some opinions about  it)
Message-Id: <3E595C2C.52896EDA@earthlink.net>

"John W. Krahn" wrote:
[snip]
> > #!/usr/bin/perl -i.bak -lw
> > use strict;
> >
> > my @pre=map sprintf('../../pics/%02d/', $_), 3..10;
> >
> > my ($cnt,$f);
> > while ($f=<>) {
> >     next if ++$cnt == @pre;
> 
> The value of $cnt starts out at 0, then you increment here to 1, then
> at the end of the loop you set it to 0 again so at this point the
> value of $cnt will ALWAYS be 1

You're not seeing the 'redo' later in the loop.

The code you provided is *not* equivilant to his code, since it never
alters the order of items in the @pre array.

If you wanted to rewrite it with clearer flow control (without the redo
and the continue block), then it would look something like this:

   #!/usr/bin/perl -i.bak -lw
   use strict;
   my @prefix = map "../../pics/$_/", "03".."10";
   while( <> ) {
      my ($cnt, $f) = 0;
      chomp;
      for my $dir ( @prefix ) {
         last if -e ($f = $dir . $_);
         ++$cnt;
      }
      next if $cnt == @prefix;
      print $f;
      push @prefix, splice @prefix, 0, $cnt if $cnt;
   }
   __END__
[untested]

The push/splice thing is equivilant to the repeated push/shift, but
should be slightly more efficient.

Depending on how files in the list are arranged, it *may* be better to
change that line to:

   unshift @prefix, splice @prefix, $cnt, 1 if $cnt;

Which is effectively a "move-to-front" operation.

-- 
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print


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

Date: Mon, 24 Feb 2003 02:14:05 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Newbie request for script review
Message-Id: <3E597FAC.4000609@rochester.rr.com>

A. Sinan Unur wrote:

 ...
> I am trying to familiarize myself with Perl. To that end, I decided to 


Wow, a CGI script using HTML::Template is a whale of a way to 
familiarize yourself with Perl -- quite a tall order.


> concoct a simple cgi script to browse images in a directory on web site. 
> The script is intended to be called in the following manner:
> 
> http://somehost.com/cgi-bin/photobrowser.pl?album/spring
> 
> As I have virtually no experience, and no feel for Perl, I would 
> appreciate  your comments about this script before I "improve" it.
> 
> BEGIN: photobrowser.pl
> 
> #!C:/Perl/bin/perl.exe -w


Well, on Windoze, the #! line doesn't do much, so one could just replace 
this with #!perl -w .  The -w is good, though, as it will be picked up 
and will turn warnings on.


> # photobrowser
> # Display links (optionally with thumbnails) to 
> # images in a directory
> 
> use strict;


Excellent!


> use HTML::Template;
> 


For a CGI script, you should definitely:

use CGI;

even though it would only be used to print headers in this script.


> # Clean up the location specified in the request by 
> # removing all relative paths 
> my $location = shift;


Very interesting -- I never knew the URL arguments could be obtained in 
this fashion.  But it does seem to work.  Where is this documented?


> if($location =~ s/(\.\.\/)|(\.\.)//g) {


OK, I guess?  You might want to prohibit some specific directories under 
your htdocs, though.


> 	print "Content: text/plain\n\nInvalid location specified in 
> request.";


Hmmm...not sure why, but this is doing a file download, with the 
filename being the name of the Perl script and the contents being the 
"Invalid location ..." string.  Maybe I don't have something configured 
correctly for text/plain .  Nope, that's not it -- I checked, a test 
program works fine.  I have no idea why it is doing that.  The filetype 
coming down is wwwserver/shellcgi .  Ah, I see why now.  It should be 
"Content-type:", not "Content:".  If you had used:

    use CGI qw(:standard);

and done

    print header,"Invalid location...";

that wouldn't have happened.


> } else {
> # Configuration Variables
> 	my $wwwroot = '';
> 	my $script_location = '/cgi-bin/photobrowser.pl';
> 	my $htdocs_path = 'C:/Program Files/Apache Group/Apache2/htdocs';
> 	my $template_path = 
>         'C:/Program Files/Apache Group/Apache2/templates';
> 	my $template_file = 'photobrowser.tmpl.html';
> 	my $photo_path = "$htdocs_path/$location";
> 	my $thumb_dir_name = 'thumb';
> 
> 	my $template = 
>         HTML::Template->new(filename => "$template_path/$template_file");
> 
> 	# Provide some information during development
> 	$template->param(HTDOCS => $htdocs_path);
> 	$template->param(LOCATION => $location);
> 	$template->param(PHOTO_PATH => $photo_path);
> 	
> 	opendir(PHOTO_DIR, $photo_path);


You should check for failure here, especially since it is user-specified


> 
> 	# For the line below, I get the warning
> 	# [Sun Feb 23 15:03:18 2003] [error] [client 127.0.0.1] 
> 	# Use of uninitialized value in concatenation (.) or string at 
> 	# C:/Program Files/Apache Group/Apache2/cgi-bin/photobrowser.pl 


That's probably because your opendir failed -- if the opendir doesn't 
fail, you don't get that -- or at least I don't.


> 	my @files = grep { !/^\.+/ && /$\.jpg/ } readdir(PHOTO_DIR);


Not sure what you are trying to do with the regex /$\.jpg/ -- that will 
interpolate $\ and insert whatever that was (it wasn't modified, so it 
will be undef, which will interpolate to the empty string) into the 
regex.  Then it will match any single character (the unescaped . ), 
followed by jpg, lowercase only.  You probably meant something more like 
/\.jpg$/i or maybe even /\.jpe?g/i .


> 
> 	closedir PHOTO_DIR;
> 	
> 	my @loop_data = ();
> 	foreach my $file (@files) {
> 		my %iter_data;
> 		$iter_data{IMGFILE} = $file;
> 		$iter_data{IMGURL} = "$wwwroot/$location/$file";
> 		if(-e "$photo_path/$thumb_dir_name/$file") {
> 			$iter_data{THUMBURL} = "$wwwroot/$location/thumb/$file";
> 		} else {
> 			$iter_data{THUMBURL} = "";
> 		}
> 		push(@loop_data, \%iter_data);

> 	}
> 	
> 	$template->param(IMGLIST => \@loop_data);
> 	print "Content-Type: text/html\n\n", $template->output;
> }
> ### END
> 
> BEGIN: Template file to use with HTML::Template
> 
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html lang="en">
>   <head>
> 	<title>Photo Browser - <TMPL_VAR LOCATION></title>
>   </head>
> 
>   <body>
> 	<table border="0" bgcolor="#dadada" cellspacing="2" cellpadding="4"
> 	>
> 	  <tr>
> 		<td bgcolor="white" align="right">HTDOCS: </td>
> 		<td bgcolor="white"><TMPL_VAR HTDOCS></td>
> 	  </tr>
> 	  <tr>
> 		<td bgcolor="white" align="right">LOCATION: </td>
> 		<td bgcolor="white"><TMPL_VAR LOCATION></td>
> 	  </tr>
> 	  <tr>
> 		<td bgcolor="white" align="right">PHOTO_PATH: </td>
> 		<td bgcolor="white"><TMPL_VAR PHOTO_PATH></td>
> 	  </tr>
> 	</table>
> 		
> 	<TMPL_LOOP IMGLIST>
> 	<a href="<TMPL_VAR IMGURL>"><TMPL_IF THUMBURL><img 
> 	  src="<TMPL_VAR THUMBURL>"
> 	  title="<TMPL_VAR IMGFILE>"><TMPL_ELSE><TMPL_VAR IMGFILE></TMPL_IF>


When there are no thumbnails, this is sort of ugly -- just a bunch of 
filenames strung together.  Works OK when there are thumbnails present, 
though.


> </a>
> 	</TMPL_LOOP>
> 	
> 	</body>
> </html>
> 
> 

-- 
Bob Walton



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

Date: 24 Feb 2003 03:34:07 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Newbie request for script review
Message-Id: <Xns932BE5954F58Dasu1cornelledu@132.236.56.8>

Bob Walton <bwalton@rochester.rr.com> wrote in
news:3E597FAC.4000609@rochester.rr.com: 

> A. Sinan Unur wrote:

 ...

>> As I have virtually no experience, and no feel for Perl, I would 
>> appreciate  your comments about this script before I "improve" it.
>> 
>> BEGIN: photobrowser.pl
>> 
>> #!C:/Perl/bin/perl.exe -w
> 
> 
> Well, on Windoze, the #! line doesn't do much, so one could just
> replace this with #!perl -w .  The -w is good, though, as it will be
> picked up and will turn warnings on.

I saw it in the printenv.pl script that came with Apache, and decided to 
emulate it.

> For a CGI script, you should definitely:
> 
> use CGI;
> 
> even though it would only be used to print headers in this script.

OK.

>> # Clean up the location specified in the request by 
>> # removing all relative paths 
>> my $location = shift;
> 
> 
> Very interesting -- I never knew the URL arguments could be obtained
> in this fashion.  But it does seem to work.  Where is this documented?

Sorry, I don't know, but I should check. I guess I must have seen it in 
someone else's code.

>> if($location =~ s/(\.\.\/)|(\.\.)//g) {
> 
> OK, I guess?  You might want to prohibit some specific directories
> under your htdocs, though.

My intent was to be able to use this script to browse images contained in 
any directory. I don't know if that is wise. Probably limit it to a photo 
album root.

>>      print "Content: text/plain\n\nInvalid location specified in 
>> request.";
> 
 ... 
> now.  It should be "Content-type:", not "Content:".  

arrrgh!!! Editing in the newsreader. I swear it it Content-type in the 
file.

> If you had used:
> 
>     use CGI qw(:standard);
> 
> and done
> 
>     print header,"Invalid location...";
> 
> that wouldn't have happened.

Cool, thanks for pointing that out.

>>      
>>      opendir(PHOTO_DIR, $photo_path);
> 
> 
> You should check for failure here, especially since it is
> user-specified 

OK.

>> 
>>      # For the line below, I get the warning
>>      # [Sun Feb 23 15:03:18 2003] [error] [client 127.0.0.1] 
>>      # Use of uninitialized value in concatenation (.) or string at 
>>      # C:/Program Files/Apache Group/Apache2/cgi-bin/photobrowser.pl 
> 
> That's probably because your opendir failed -- if the opendir doesn't 
> fail, you don't get that -- or at least I don't.

I rechecked. It looks like you are right.

>>      my @files = grep { !/^\.+/ && /$\.jpg/ } readdir(PHOTO_DIR);
> 
> 
> Not sure what you are trying to do with the regex /$\.jpg/ -- that
> will interpolate $\ and insert whatever that was (it wasn't modified,
> so it will be undef, which will interpolate to the empty string) into
> the regex.  Then it will match any single character (the unescaped .
> ), followed by jpg, lowercase only.  You probably meant something more
> like /\.jpg$/i or maybe even /\.jpe?g/i .

Yes, I meant to place the $ at the end. I had assumed that $ modified the 
pattern that came after it to be anchored at the end (does that sentence 
make sense? I don't know how else to explain my motivation.) Thank you for 
spotting it.
 
> When there are no thumbnails, this is sort of ugly -- just a bunch of 
> filenames strung together.  Works OK when there are thumbnails
> present, though.

Eventually, I would like to put the links/thumbnails in a table where the 
width is specified as a configuration parameter. I am having difficulty 
figuring out the nested <TMPL_LOOP>s and the associated data structure I 
need to construct in Perl. I have read the relevant paragraph in the 
HTML::Template pod several times, but it just hasn't sunk in yet.

Another planned extension is optionally reading image descriptions from 
file stored in the image directory.

Thank you for your comments.

Sinan.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: Sun, 23 Feb 2003 18:54:14 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Newbie request for script review
Message-Id: <slrnb5ir9m.cru.tadmc@magna.augustmail.com>

A. Sinan Unur <asu1@c-o-r-n-e-l-l.edu> wrote:

> I am trying to familiarize myself with Perl. To that end, I decided to 
> concoct a simple cgi script


You should learn to crawl before running in a race.

Learn Perl from the command line first.

CGI applications are not "simple", there are several advanced
aspects to them, such as multitasking and security.


> I would 
> appreciate  your comments about this script before I "improve" it.

> #!C:/Perl/bin/perl.exe -w
> use strict;


Good. Very good.


> if($location =~ s/(\.\.\/)|(\.\.)//g) {
                    ^^^^^^^^^
                    ^^^^^^^^^

You don't need that part, the 2nd part will match that too.

No need for the s///g option either.


> # Configuration Variables
> 	my $wwwroot = '';
> 	my $script_location = '/cgi-bin/photobrowser.pl';
> 	my $htdocs_path = 'C:/Program Files/Apache Group/Apache2/htdocs';
> 	my $template_path = 
>         'C:/Program Files/Apache Group/Apache2/templates';
> 	my $template_file = 'photobrowser.tmpl.html';
> 	my $photo_path = "$htdocs_path/$location";
> 	my $thumb_dir_name = 'thumb';


Consider putting all of those in a single hash instead:

   $config{wwwroot} = '';
   $config{script_location} = '/cgi-bin/photobrowser.pl';
   ...


> 	# Provide some information during development
> 	$template->param(HTDOCS => $htdocs_path);
> 	$template->param(LOCATION => $location);
> 	$template->param(PHOTO_PATH => $photo_path);
> 	
> 	opendir(PHOTO_DIR, $photo_path);


You may not get what you asked for.

You should check to see if you got it:

  opendir(PHOTO_DIR, $photo_path) or die "could not open '$photo_path' dir $!";


> 	# For the line below, I get the warning
> 	# [Sun Feb 23 15:03:18 2003] [error] [client 127.0.0.1] 
> 	# Use of uninitialized value in concatenation (.) or string at 
> 	# C:/Program Files/Apache Group/Apache2/cgi-bin/photobrowser.pl 
> 	my @files = grep { !/^\.+/ && /$\.jpg/ } readdir(PHOTO_DIR);
                                       ^^
                                       ^^

$\ is the "output record separator" special variable.

It defaults to undef (uninitialized).

Backslash the dollar sign if you really want to match a dollar sign char.

All of the messages that perl might issue are documented in:

   perldoc perldiag

You should look there for any messages you get as a first step in debugging.

Or you can arrange to have perl look up messages for you, as
described in the Posting Guidelines that are posted here frequently.


> 	my @loop_data = ();


my() guarantees an empty array, there is no need to initialize 
it to an empty list.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 24 Feb 2003 04:10:45 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Newbie request for script review
Message-Id: <Xns932BEBCB8F41Basu1cornelledu@132.236.56.8>

tadmc@augustmail.com (Tad McClellan) wrote in
news:slrnb5ir9m.cru.tadmc@magna.augustmail.com: 

> A. Sinan Unur <asu1@c-o-r-n-e-l-l.edu> wrote:
> 
>> I am trying to familiarize myself with Perl. To that end, I decided
>> to concoct a simple cgi script
> 
> You should learn to crawl before running in a race.
> 
> Learn Perl from the command line first.
> 
> CGI applications are not "simple", there are several advanced
> aspects to them, such as multitasking and security.

All valid points. I just learn better in the course of building something 
that is geared towards helping me solve an immediate problem. I have been 
generating (using m4 and some shell utilities) my photo albums off-line 
and uploading them, and I thought it would be a good idea to try 
something that could replace that.

>> I would 
>> appreciate  your comments about this script before I "improve" it.
> 
>> #!C:/Perl/bin/perl.exe -w
>> use strict;
> 
> Good. Very good.
> 
> 
>> if($location =~ s/(\.\.\/)|(\.\.)//g) {
>                     ^^^^^^^^^
>                     ^^^^^^^^^
> 
> You don't need that part, the 2nd part will match that too.
> No need for the s///g option either.

I noticed that a few hours after my post.

>> # Configuration Variables
>>      my $wwwroot = '';
 ...
> 
> 
> Consider putting all of those in a single hash instead:
> 
>    $config{wwwroot} = '';
>    $config{script_location} = '/cgi-bin/photobrowser.pl';
>    ...

OK.

>>      opendir(PHOTO_DIR, $photo_path);
> 
> You may not get what you asked for.
> 
> You should check to see if you got it:
> 
>   opendir(PHOTO_DIR, $photo_path) or die "could not open '$photo_path'
>   dir $!"; 

I am a little confused about whether it is OK to use die in CGI scripts. 
Admittedly, I have some reading to do but maybe someone can help clear it 
up for me, especially if the script might run under mod_perl in Apache.

>>      # For the line below, I get the warning
 ...

> All of the messages that perl might issue are documented in:
> 
>    perldoc perldiag
> 
> You should look there for any messages you get as a first step in
> debugging. 
> 
> Or you can arrange to have perl look up messages for you, as
> described in the Posting Guidelines that are posted here frequently.

I did not know about that feature. Thanks.

>>      my @loop_data = ();

> my() guarantees an empty array, there is no need to initialize 
> it to an empty list.

Blind copying from the HTML::Template podwithout paying too much 
attention to context. My bad.

Thanks for the help.

Sinan.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: 23 Feb 2003 18:34:37 -0800
From: autrijus@autrijus.org (Autrijus Tang)
Subject: Re: Perl & VB without activeperl on Windows??
Message-Id: <12bcf56.0302231834.624a45b8@posting.google.com>

nobody <noemail@nowhere.net> wrote in message news:<Xns93269777FF4D0abccbaabc@129.250.170.99>...
> >>>> ... is there something I can do to allow my vb and perl program to
> >>>> work together on a windows machine without activeperl??!! 
> >>> You could use ActiveState's PerlApp utility to make your Perl
> >>> script into an .exe. ...
> >> Or take a look at PAR.pm on CPAN.
> > Sounds cool! Esp. "pp".
> 
> (replying to myself)
> But it still needs core Perl on the target machine. :(

Uh no, it doesn't.  The unadored executables generated by 'pp' needs
no core perl on the target machine -- although if the perl is built
as a shared library, it will then need a perl58.dll (or perl56.dll,
etc) in the path.

Would you tell me (via email to par@perl.org) which part of my 
documentation indicated that it requires core perl?  I'd like to 
correct it if possible. :-)

Thanks,
/Autrijus/


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

Date: Mon, 24 Feb 2003 01:07:27 +0200
From: CM <eleos111@hotmail.com>
Subject: Re: Problem installing Perl dbd::mysql in Windows XP. Please help!
Message-Id: <30li5vkian9qesqpm8qput5hb5sp5lddr6@4ax.com>

On Sun, 23 Feb 2003 16:28:56 -0600, "Randy Kobes"
<randy@theoryx5.uwinnipeg.ca> wrote:

>"CM" <eleos111@hotmail.com> wrote in message
> news:3m5h5vgt2s97mkdfd9di2n2a09839mtqh3@4ax.com...
>> I have tried to install Perl (ActivePerl 5.8.0 and 5.6.1) in Windows
>> XP with IIS and mysql 4. I also added DBI module with the command
>> install DBI
>> and added dbd-mysql with command:
>> install
>> ftp://ftp.de.uu.net/pub/CPAN/authors/id/JWIED/DBD-mysql-1.2212.x86.ppd
>>
>> But when I try to run a specific script I always get the follow error:
>> [Sat Feb 22 23:49:01 2003]
>> C:\Inetpub\wwwroot\cgi\phpBBusers2nukeusers.pl: install_driver(MySQL)
>> failed: Can't load 'C:/Perl/site/lib/auto/DBD/mysql/mysql.dll' for
>> module DBD::mysql: load_file:The specified module could not be found
>> at C:/Perl/lib/DynaLoader.pm line 206.
>
>For one thing, ActivePerl 6xx and 8xx are binary incompatible,
>so this package might be expected to work only with the Perl
>version it was compiled with. But also, it might be that this
>DBD-mysql package was compiled against mysql-3.xx, rather
>than version 4 (I've seen reports that the two aren't binary
>compatible in this context). Do you have mysql-3 also installed
>that you could try?
>
>best regards,
>randy kobes
>
>

Ok, will download mysql 3.xx and try with it too and let the group now
for future reference...
thanks for the info...



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

Date: Mon, 24 Feb 2003 12:47:37 +1100
From: Dave Horsfall <daveh@ci.com.au>
Subject: Pushing onto hash of hash of array
Message-Id: <20030224123341.X51405@mippet.ci.com.au>

I must have a mental block...  I have a structure that looks like this:

  %entry =
  (
    dn1 =>
    {
      attr1 => [ "value1-a", "value1-b" ],
      attr2 => [ "value2" ]
    },
    dn2 =>
    {
      attr1 => [ "value1" ]
    }
  );

It's a hash of hashes of variable-length arrays, if that makes sense (and
if it looks like LDAP, yes, you're right).

How do I push another element on to one of those arrays?  The "obvious"
method "push $entry{$dn}{$attr}, $val", says "Type of arg 1 to push must
be array (not hash elem)" so plainly I need to coerce it to be an array
reference.  I've tried just about everything in the Camel Book (Mk III) to
no avail.

If you're going to reply, please email as well, as my news server is
having a hissy fit, and I only see about half the posted articles.

--
Dave Horsfall  DTM  VK2KFU  daveh@ci.com.au  Ph: +61 2 9906-7866  Fx: 9906-1556
Corinthian Engineering, Level 1, 401 Pacific Hwy, Artarmon, NSW 2064, Australia


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

Date: Mon, 24 Feb 2003 03:16:19 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Pushing onto hash of hash of array
Message-Id: <pan.2003.02.24.02.16.01.830462@aursand.no>

On Mon, 24 Feb 2003 12:47:37 +1100, Dave Horsfall wrote:
> [...]
> How do I push another element on to one of those arrays?  The
> "obvious" method "push $entry{$dn}{$attr}, $val", says "Type of
> arg 1 to push must be array (not hash elem)" [...]

That's right; you're trying to push the new value into the hash itself,
which - obviously - won't work.

Try this instead;

  push( @{$entry{'dn1'}->{'attr1'}}, 'value1-c' );


-- 
Tore Aursand - tore@aursand.no - http://www.aursand.no/



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

Date: Mon, 24 Feb 2003 02:31:26 -0000
From: "Peter Cooper" <newsfeed2@boog.co.uk>
Subject: Re: Pushing onto hash of hash of array
Message-Id: <wvf6a.2303$EN3.18731@newsfep4-glfd.server.ntli.net>

Dave,

> How do I push another element on to one of those arrays?  The "obvious"
> method "push $entry{$dn}{$attr}, $val", says "Type of arg 1 to push must
> be array (not hash elem)" so plainly I need to coerce it to be an array
> reference.  I've tried just about everything in the Camel Book (Mk III) to
> no avail.

push (@{${$entry{dn1}}{attr1}}, "test");
print @{${$entry{dn1}}{attr1}};

will work.. as will..

push (@{$entry{dn1}->{attr1}}, "test");
print @{$entry{dn1}->{attr1}};

Pete




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

Date: Mon, 24 Feb 2003 03:05:31 -0000
From: "Peter Cooper" <newsfeed2@boog.co.uk>
Subject: Re: Pushing onto hash of hash of array
Message-Id: <Y_f6a.2314$EN3.18842@newsfep4-glfd.server.ntli.net>

> If you're going to reply, please email as well, as my news server is
> having a hissy fit, and I only see about half the posted articles.

I did, and your mail server says my mail server is blacklisted.

Just letting you know, as tens of thousands of people use the NTLWorld SMTP
server.

Pete




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

Date: Sun, 23 Feb 2003 21:49:51 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Switch order of sprintf conversions
Message-Id: <3E59884F.427A0016@earthlink.net>

Gunnar Hjalmarsson wrote:
[snip]
> > According to the perl5.8.0 documentation for sprintf:
> >
> >    printf '%3$d %d %1$d', 1, 2, 3;  # prints "3 1 1"
> 
> Hmm.. I failed to find the v5.8.0 docs for sprintf on line, but
> perldelta talks about parameter *reordering*.

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

> > Your function, given those arguments, produces "3 1 2"... oops.
> 
> Yeah, that was intended...
> 
> > Perhaps something like the following will do:
[snip]
> > This correctly produces "3 1 1"
> > when given ('%3$d %d %1$d', 1, 2, 3).
> 
> But why do you do it that simple, when it can be done much more
> complicated?? ;-)

Well, it doesn't *have* to be simple :)

I decided to look at the source to find out who introduced the change,
and whlie looking, I found the following comment in perl's sprintf
engine (Perl_sv_vcatpvfn):

/*
    We allow format specification elements in this order:
        \d+\$              explicit format parameter index
        [-+ 0#]+           flags
        v|\*(\d+\$)?v      vector with optional (optionally specified) arg
        0                  flag (as above): repeated to allow "v02"
        \d+|\*(\d+\$)?     width using optional (optionally specified) arg
        \.(\d*|\*(\d+\$)?) precision using optional (optionally specified) arg
        [hlqLV]            size
    [%bcdefginopsux_DFOUX] format (mandatory)
*/

Taking into account the use of the *other* places where \d+\$ can occur
would make the function more complicated, but it's still doable:

sub sprintfmt {
   my $fmt = shift;
   my ($i, @p) = 0;
   $fmt =~ s[(
      %
      (?:(\d+)\$)?
      [-+ 0#]*
      (?:(?:\*(?:\d+\$)?)?v)?
      0?
      (?:\d+|\*(?:\d+\$)?)?
      (?:\.(?:\d*|\*(?:\d+\$)?))?
      [hlqLV]?
      [%bcdefginopsux_DFOUX]
   )]{
      my $use_i = !$2;
      my $pat = $1;
      push @p, $1-1 while $pat =~ s/(\d+)\$//;
      push @p, $i++ if $use_i;
      $pat;
   }xge;
   sprintf $fmt, @_[@p];
}
__END__
[untested]

How's that for complicated? :)

> > I think that it would be most convenient if your function (and hence
> > your data) is compatible with perl5.8.0's handling of the issue. 
> > That way, when you upgrade to 5.8, you can discard your sprintfmt
> > function and use perl's builtin sprintf without needing to change
> > your data.
> 
> I agree on that, but I'm still hesitating, since I can't help
> wondering if the behaviour is intended, or if it is a bug. Do you
> know how to find somebody who would be able to tell?

I suppose that the person who put it in... I've been trying to look
through the Changes5.8 file, but it's a gargantuan file.  I suppose that
if you really want to know, I could go ask on the perl5porters mailing
list, to find out how put it in.

Or, perhaps google will be able to find you some documentation elsewhere
describing how <position>$ is supposed to work in (s)printf.

-- 
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print


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

Date: Mon, 24 Feb 2003 02:13:52 GMT
From: "Seth Brundle" <brundlefly76@hotmail.com>
Subject: What the heck is the scope if $/???
Message-Id: <Adf6a.68133$Ik.2956150@typhoon.sonic.net>

I just spent hours debugging the following:

In a mod_perl module, I call one of my own (non-mod-perl) module subroutines
which does the following:

sub menu_trail{
        open(TRAILER,'/templates/trailer.tmpl');
        {
        undef $/;
        return <TRAILER>;
        }
}

The effect of this was that 1/20 requests, the following sub in totally
seperate (non-od-perl) module called by the same mod_perl module:

foreach(<SOMEOTHERFILE>){
    print;
}

Was exhibiting behaviour as if $/ was undefined! (i.e., the first iteration,
the entire file was sucked into $_, newlines and all).

This is totally bizarre - first of all, because I thought $/ had a local
scope, so the first sub should not have affectted ANYTHING outside of its
local curly brackets. Second, if I am wrong about $/'s scope, or if it has
different scope within a mod_perl environment, then why the heck did it work
19 times out of 20?

Finally, the weirdest of all: during debugging I was actually printing out
the value of $/ in the error log, and it was indeed a newline  wtf!!

The minute I commented out the undef, everything worked fine.

WEIRD!




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

Date: Sun, 23 Feb 2003 21:53:41 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: What the heck is the scope if $/???
Message-Id: <3E598935.3BFC74E1@earthlink.net>


The scope of $/ is global to your entire program.

Instead of simply doing 'undef $/', you should do 'local $/'.

If you make that change, all your problems will go away.

-- 
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print


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

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.  

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


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