[25939] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8158 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 9 06:05:22 2005

Date: Thu, 9 Jun 2005 03:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 9 Jun 2005     Volume: 10 Number: 8158

Today's topics:
        Masking by columns for grep <shanen@cashette.com>
    Re: Masking by columns for grep <shanen@cashette.com>
    Re: Masking by columns for grep <john@castleamber.com>
    Re: Masking by columns for grep <shanen@cashette.com>
    Re: Multilanguage capable scripts howto? <krienke@uni-koblenz.de>
    Re: Net::FTP: cwd(' ') <josef.moellers@fujitsu-siemens.com>
    Re: perl one liner to display the third line from the e <bart.lateur@pandora.be>
        report generator <_nospam_stigerikson@yahoo.se>
        unitialized value error <alexj@freesurf.ch>
    Re: unitialized value error <someone@example.com>
    Re: unitialized value error <alexj@freesurf.ch>
    Re: unitialized value error <noreply@gunnar.cc>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 9 Jun 2005 13:46:23 +0900
From: "Shannon Jacobs" <shanen@cashette.com>
Subject: Masking by columns for grep
Message-Id: <42a7ccb5_4@news1.prserv.net>

I want to restrict a grep to certain columns. After extensive contemplation 
and a lot of study of the camel book (1991 printing), various manuals and 
Web pages, and assorted newsgroup posts, I finally indirectly arrived at 
this:

  @foo2 = grep(/.{50}$form_values{'a_SEARCH_VALUE'}.{6}/,@foo1);

That's how it appears in the actual file, though for the sake of this 
question, a reduced form would be:

@foo = grep(/.{50}$theString.{6},@foo);

The "records" are fixed length, and I want to ignore the first 50 characters 
and the last 6. This approach mostly works (unless the string has a | in it, 
which is probably a different problem), but it seems to have pegged my 
nauseous code detector. I'm interested in constructive suggestions or 
bemusing feedback. (Or maybe I should just appeal for a reference to a 
source to replace the entire grotesque thing, appealing to the camel page 
xviii citation of "laziness" as the first great virtue. Right now this thing 
feeds off of another database system that goes back over 20 years, and it 
would probably be a good thing to port the entire mess to some reasonable 
environment...)

For the sake of context, the entire program appears below. It is actually 
live on the Web at shanenj.tripod.com/search0.html. (Yes, I know Tripod has 
a brain-damaged interface, but returning the encoded error messages in the 
URL is kind of unique. I also know I should move to a decent server. 
Consider Perl/CGI on Tripod as one of those semi-religious rituals, rather 
like flogging oneself with a chain.)

Warning: If you proceed past this point you are at risk of laughing yourself 
sick. By any standard, I'm sure this is some really peculiar old code, 
containing about 10 years of occasional hacking and tweaking. I think it was 
the Lisp influence that did it... Or maybe the parts that came from the 
Chinese guy with the Berkeley Ph.D.? (I'm sure he doesn't want a more 
explicit citation for what I've done to his code.) Or the Y2K windowing? Or 
something. <Imagine a movie of the "Lost in Space" robot wildly waving its 
arms and shouting "Danger, Will Robinson! Danger!">

#!/usr/local/bin/perl

print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
print "Content-type: text/html\n\n";

print "<HTML><HEAD><TITLE>Search Result</TITLE>\n";
print '<SCRIPT language="JavaScript" src="../formfunc.js"></SCRIPT>';
print "\n";
print '<SCRIPT language="JavaScript">var inHTMLdate = "';
print scalar localtime;
print '";</SCRIPT>';
print "\n";
print "</HEAD>\n";
print "<BODY bgcolor=\"#00bfbf\">\n";

print "<hr size=8>\n";
print "<center><h3>BookList Search Form Result</H3></center>\n";
print "<hr size=8>";

%form_values = &html_parse;

if ( $form_values{'a_SEARCH_VALUE'} ) {
 open(DATAFILE,'titles.txt');
 $i = 0;
 while (<DATAFILE>) { $foo0[$i++] = $_; }
 close(DATAFILE);

 open(AUTHFILE,'authors.txt');
 $i = 1;
 while (<AUTHFILE>) { $authlist[$i++] = $_; }
 close(AUTHFILE);

# Time for fishing against authors (Main event of 8JUN2005)
 if ($form_values{'AuthorFishing'} eq 'gofish' ) {
  @foobar = grep(/$form_values{'a_SEARCH_VALUE'}/i,@authlist);
  $form_values{'a_SEARCH_VALUE'} = '';
  foreach $GREPPED (@foobar) {
   $form_values{'a_SEARCH_VALUE'} = 
$form_values{'a_SEARCH_VALUE'}.substr($GREPPED,34,4)."|";
   }
  $form_values{'a_SEARCH_VALUE'} = $form_values{'a_SEARCH_VALUE'}."90AZ";
}

# Main searches from here
 if ($form_values{'sorttype'} eq 'title' ) {
  @foo1 = sort ignore3 @foo0
 } else { if ($form_values{'sorttype'} eq 'subject') {
  @foo1 = sort {substr($a,62,6) cmp substr($b,62,6)} @foo0
 } else {
  @foo1 = @foo0
 }}

 if ($form_values{'searchfields'} eq 'authornums' ) {
  @foo2 = grep(/.{50}$form_values{'a_SEARCH_VALUE'}.{6}/,@foo1);
# fut } else { if ($form_values{'searchfields'} eq 'dates' ) {
#  @foo2 = grep(/$form_values{'a_SEARCH_VALUE'}/,@foo2);
# } else { if ($form_values{'searchfields'} eq 'subjects' ) {
# fut  @foo2 = grep(/$form_values{'a_SEARCH_VALUE'}/,@foo2);
 } else {
  @foo2 = @foo1
 }

 if ($form_values{'sensecase'} eq 'usecase' ) {
  @foo3 = grep(/$form_values{'a_SEARCH_VALUE'}/,@foo2);
 } else {
  @foo3 = grep(/$form_values{'a_SEARCH_VALUE'}/i,@foo2);
 }

 $hits = 1+$#foo3;
 print ("<center>This search ( $form_values{'a_SEARCH_VALUE'} ) found $hits 
books.</center><p>\n");

 if ($form_values{'datetype'} eq 'human' ) {
#only load $months once if required
  $months[1] = 'January';
  $months[2] = 'February';
  $months[3] = 'March';
  $months[4] = 'April';
  $months[5] = 'May';
  $months[6] = 'June';
  $months[7] = 'July';
  $months[8] = 'August';
  $months[9] = 'September';
  $months[10] = 'October';
  $months[11] = 'November';
  $months[12] = 'December';
}

 print("<center><table border = 1 cell padding = 1>\n");
 print("<th>Title of Book</th><th>Pub. Year</th><th>Date Read</th>\n");
 print("<th colspan=\"3\">Authors</th><th colspan=\"3\">Subjects</th>\n");
 print("<tr></tr><tr></tr>\n");
 foreach $GREPPED (@foo3) {
  print("<tr>");
  print("<td>",substr($GREPPED,0,40),"</td>\n");
  print("<td>",substr($GREPPED,40,4),"</td>");

#  print("<td>",substr($GREPPED,44,6),"</td>");
  print("<td>".nicedate(substr($GREPPED,44,6))."</td>");

#  From here store the authors and get names if required
  $auth1 = substr($GREPPED,50,4);
  $auth2 = substr($GREPPED,54,4);
  $auth3 = substr($GREPPED,58,4);

  if ( $form_values{'numorname'} eq 'authnames' ) {
   print("<td>".substr($authlist[$auth1],0,34)."<br></td>");
   print("<td>".substr($authlist[$auth2],0,34)."<br></td>");
   print("<td>".substr($authlist[$auth3],0,34)."<br></td>\n");
  } else { if ( $form_values{'numorname'} eq 'both' ) {
   print("<td>".substr($authlist[$auth1],0,34)."( $auth1 )<br></td>");
   print("<td>".substr($authlist[$auth2],0,34)."( $auth2 )<br></td>");
   print("<td>".substr($authlist[$auth3],0,34)."( $auth3 )<br></td>\n");
  } else {
   print("<td>$auth1<br></td>");
   print("<td>$auth2<br></td>");
   print("<td>$auth3<br></td>\n");
  }}

#  print("<td>",substr($GREPPED,50,4),"<br></td>");
#  print("<td>",substr($GREPPED,54,4),"<br></td>");
#  print("<td>",substr($GREPPED,58,4),"<br></td>\n");

  print("<td>",substr($GREPPED,62,2),"<br></td>");
  print("<td>",substr($GREPPED,64,2),"<br></td>");
  print("<td>",substr($GREPPED,66,2),"<br></td>");
  print("</tr>\n\n");
 }
 print("</table></center>\n");
} else {
 print ("Nothing to Search For<br>\n");
}
print '<SCRIPT language="JavaScript">';
print "\n";
print 'threefooter(\'Return 
to<br>shanen\\\'s<br>Home\',\'/index.html\',\'procbook\');';
print "\n";
print '</SCRIPT>';
print "\n";

# print "<hr size=8>";
# print "<center><P>End of Search Results<P><br>\nClick to go back to my 
Index page </center>\n";
# print "<P><center>";

# print "<A http=\"/index.html\"><img src=\"/images/home.gif\" 
border=0></a>";
# print "</center><P>";
# print "<hr size=8><P>";

print "</BODY></HTML>";

exit(0);

sub ignore3 {
# local ($acut,$bcut);
 $acut = 0;
 $bcut = 0;
 if (index($a,'A ') == 0) {$acut = 2}
 if (index($a,'An ') == 0) {$acut = 3}
 if (index($a,'The ') == 0) {$acut = 4}
 if (index($b,'A ') == 0) {$bcut = 2}
 if (index($b,'An ') == 0) {$bcut = 3}
 if (index($b,'The ') == 0) {$bcut = 4}
#print ("$a1 cmp $b1");
 substr($a,$acut) cmp substr($b,$bcut)
# $a cmp $b
}

sub nicedate {
 if ($form_values{'datetype'} eq 'human' ) {
  if (substr(@_[0],4,1) eq '0') {
                                 $foo = $months[substr(@_[0],2,2)].' 
'.substr(@_[0],5,1)
  } else {
                                 $foo = $months[substr(@_[0],2,2)].' 
'.substr(@_[0],4,2)
                             };

# Y2K window added to 1960-2059, slj 3/20/2000 including above #s
if (substr(@_[0],0,1) gt '5') {
   $foo.', 19'.substr(@_[0],0,2)
} else {
   $foo.', 20'.substr(@_[0],0,2)
}
# Yeah, I know it isn't pretty but I haven't touched PERL in a LONG time...

 } else {
  if ($form_values{'datetype'} eq 'usa' ) {
  substr(@_[0],2,2).'/'.substr(@_[0],4,2).'/'.substr(@_[0],0,2)
  } else {
  @_[0]
  }
 }
}

sub html_parse
{
    local($line, $length, $offset, @pairs);

#    if ($ENV{"REQUEST_METHOD"} eq "GET") {
# $line = $ENV{"QUERY_STRING"};
#    }
#    elsif ($ENV{"REQUEST_METHOD"} eq "POST") {
#
# ($ENV{"CONTENT_TYPE"} ne "application/x-www-form-#urlencoded") &&
#     &html_fatal("Illegal Content-Type '" . $ENV
# $length = $ENV{"CONTENT_LENGTH"};
# (($length =~ m/^\d+$/) == 0) &&
#     &html_fatal("Content-Length variable not found");
#
# (read(STDIN, $line, $length) == $length) ||
#     &html_fatal("Could not read form info from stdin: " .
#$length);
#    }
#    else {
# &html_fatal("Illegal Request-Method '" . $ENV
#{"REQUEST_METHOD"} . "'");
#    }
# Probably not allowed to check ENV so just take the query string?
# Just use a GET and the one line?
     $line = $ENV{"QUERY_STRING"};

    ((!defined($line)) || (length($line) == 0)) &&
 &html_fatal("No values passed in");

    @pairs = split(/[=&]/, $line);
    (substr($line, $length - 1, 1) eq "=") &&
 ($pairs[@pairs] = "");
    $offset = 0;
    foreach $value (@pairs) {
 ($offset++ & 1) &&
     &html_unescape($value);
    }
    return @pairs;
}

sub html_unescape
{
    local($offset);

    $_[0] =~ s/\+/ /g;
    $offset = -1;
    while (($offset = index($_[0], "%", $offset + 1)) >= 0) {
 substr($_[0], $offset, 3) =
     pack("c", hex(substr($_[0], $offset + 1, 2)));
    }
}


sub html_fatal
{
    print "<H3>Error Detected</H3><P>";
    print @_[0], "\n";
    exit 0;
}



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

Date: Thu, 9 Jun 2005 13:48:22 +0900
From: "Shannon Jacobs" <shanen@cashette.com>
Subject: Re: Masking by columns for grep
Message-Id: <42a7cd2b_2@news1.prserv.net>

Shannon Jacobs wrote:
<snip> 
> @foo = grep(/.{50}$theString.{6},@foo);

Should be:

@foo = grep(/.{50}$theString.{6}/,@foo);



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

Date: 9 Jun 2005 05:28:36 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Masking by columns for grep
Message-Id: <Xns96704B059FDBcastleamber@130.133.1.4>

Shannon Jacobs wrote:

> For the sake of 

our sanity, first many tips:


> #!/usr/local/bin/perl

CGI, so add -T to the end of that line

and next:

use strict;
use warnings;


> print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
> Transitional//EN">'; print "Content-type: text/html\n\n";

Ouch! You should print the header first...

And since it's CGI:

use CGI::Carp qw(fatalsToBrowser);
use CGI;

my $cgi = new CGI;

print $cgi->header;

next: here docs, instead of:

> print "<HTML><HEAD><TITLE>Search Result</TITLE>\n";
:
:

> print "<center><h3>BookList Search Form Result</H3></center>\n";
> print "<hr size=8>";

print <<HTML;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    	<head>
    	<title>....
:
:
<hr size="8">
HTML


> %form_values = &html_parse;

Don't use & in front of a sub, unless you need it's special effects.

throw away that CGI for Dummies (1996)

> if ( $form_values{'a_SEARCH_VALUE'} ) {
>  open(DATAFILE,'titles.txt');

    	or die

>  $i = 0;
>  while (<DATAFILE>) { $foo0[$i++] = $_; }
>  close(DATAFILE);

    	or die
> 
>  open(AUTHFILE,'authors.txt');

    	or die
>  $i = 1;
>  while (<AUTHFILE>) { $authlist[$i++] = $_; }
>  close(AUTHFILE);

    	or die
>  $hits = 1+$#foo3;

$hits = @foo3;

use clear names.

>   $months[1] = 'January';

:

>   $months[12] = 'December';


aargh:

my @months = qw( January February ...... December );

if you really need 1 based, put a dummy before January

>  foreach $GREPPED (@foo3) {

Don't use ALLCAPS for non-constant scalars

[ snip ]

A *lot* of stuff that could be made more readable with here docs.

> # Yeah, I know it isn't pretty but I haven't touched PERL in a LONG
> time...

10 years?
 
> sub html_parse

Dump that one

> sub html_fatal

With fatals to browser you can just use die

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: Thu, 9 Jun 2005 17:45:45 +0900
From: "Shannon Jacobs" <shanen@cashette.com>
Subject: Re: Masking by columns for grep
Message-Id: <42a804ce_4@news1.prserv.net>

John Bokma wrote:
> Shannon Jacobs wrote:
>
>> For the sake of
>
> our sanity, first many tips:

Well, thanks, and you show some of the third virtue, hubris, but I'm not 
sure how many of these tips apply to the environment of Tripod. To call 
Tripod's CGI/Perl interface "twisted" is a charitable description, but 
"lobotomized" is probably more accurate. I'm pretty sure I tried a number of 
these things, especially in your early recommendations. I'm not even sure 
the here docs worked properly in that environment, though it has also been a 
long time since I tried those experiments. (That was probably during the 
time when I was running the same code on two or three servers, and Tripod 
was definitely the LCD. The Tripod version only survived because it's a 
reasonably stable system, and because it's hard to argue with the price.) It 
would be nice if you would have included a bit of explanation for some of 
the less obvious parts. For example, I think there's something non-obvious 
about the "or die", since I already knew about it, and I'm reasonably sure 
it was used in the original code. There must have been some reason I took it 
out here...

<snipping to conserve resources in the reply>



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

Date: Thu, 09 Jun 2005 08:51:02 +0200
From: Rainer Krienke <krienke@uni-koblenz.de>
Subject: Re: Multilanguage capable scripts howto?
Message-Id: <d88osn$6cc$1@news.uni-koblenz.de>

A. Sinan Unur wrote:

> 
> Not true:
> 
>> that it the filename had to be according to the name of the package
>> ("t") and that in auto/ there should be a structure like it is in
>> /usr/share/locale i.e. subdirectories with the locale names like
>> de_DE or en_US, ... But this was not true.
> 
> From the module documentation:
> 
> SYNOPSIS
> 
> Minimal setup (looks for auto/Foo/*.po and auto/Foo/*.mo):
> 
>     package Foo;
> 

Well and exactly in auto/Foo it does not seem to search the files. At least
it did not for me. It found them only in auto/Foo.mo . Besides the
Documentation does really not say any word about where exactly in the
filesystem the default place for "auto" is, which would also be interesting
to know I think? I still do not know this. Because of this I set the Path
explicitly. Next the description of the docs  

"Minimal setup (looks for auto/Foo/*.po and auto/Foo/*.mo)"

is misleading if you do not what "*" should stand for. Now I know it stands
for the the language name but it could have been anything else as well. The
documentation could simply say: auto/Foo/*.mo, where *.mo stands for the
language mo-file like de.mo etc or something like this. This would make
things clearer.

Thanks
Rainer


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

Date: Thu, 09 Jun 2005 09:01:20 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Net::FTP: cwd(' ')
Message-Id: <d88pb9$ctq$1@nntp.fujitsu-siemens.com>

Damian James wrote:

>>If I remove the check for a non-blank character, I get
>>"Invalid number of arguments." as the result of $ftp->message.
>>None of '\ ', '\\ ', '" "' work.
>=20
>=20
> What happens when you try to cwd into ' ' with an interactive ftp clien=
t?

Hmm, good question.
I thought that I had been able to do a 'cd " "' and that would work.=20
When I try this now, I get exactly the same error messages perl gives me.=


I did try this on various systems, though, two of them were different=20
releases of SuSE Linux (9.0 and 9.1), and I think I also tried this on a =

proprietary system. Maybe it worked on the latter.

I think I'll dig through the Net::Ftp, Net::Cmd and related stuff some mo=
re.
It has now become more of an academic question: I have talked to the=20
admin of the remote system and she changed the directory name to=20
something more accessable.

Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: Thu, 09 Jun 2005 08:19:28 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: perl one liner to display the third line from the end of a file
Message-Id: <bmufa1pd19fom9vmt861mv75d8d0dn8dab@4ax.com>

Oxnard wrote:

>Assuming the file is a random length text file.

Try File::ReadBackwards.

	<http://search.cpan.org/search?module=File::ReadBackwards>

-- 
	Bart.


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

Date: Thu, 09 Jun 2005 10:17:17 +0200
From: stig <_nospam_stigerikson@yahoo.se>
Subject: report generator
Message-Id: <d88tsm$9vt$1@oden.abc.se>

hi.
are there any "good ways" or any modules that can be used to create report forms 
in a simple manner.

from time to time users demand new reports to be created from data in a 
database, the reports are presented in a web interface.

the problem is that every time the users need a new report, the developers need 
to write a few lines of code and change a few templates.
if possible it would be good if the users could specify new reports themselfs or 
at least if the developers could use some report genarator to speed up the process.

any ideas?

/stig


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

Date: Thu, 09 Jun 2005 06:37:44 +0200
From: Alexandre Jaquet <alexj@freesurf.ch>
Subject: unitialized value error
Message-Id: <42a7c79d$0$1161$5402220f@news.sunrise.ch>

Hi,

I can't figure why I'm getting this error with my code.

I've initialized all my var at the begining of my script


but righ here :  s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
I got error : Use of unitialized variable in substitution iterator

simple test script :

#!perl -w
use strict;

my $lang, my $CGISESSID,
my $LANG, my %VINYL, my %SESSION,  my %SERVER,
my %ERROR,
my %PAYPALL, my %WISHLIST;



%WISHLIST = ();
%PAYPALL = ();
%ERROR = ();
$LANG = "";
%VINYL = ();
%SESSION = ();
%SERVER = ();

#should test for non %00 url encoding ...

my $dir = "C:/indigoperl/apache/htdocs/recordz/";
open (FILE, "<$dir/main.html") or die "cannot open file $dir/main.html";
my $string = "simple test";
	while (<FILE>) {	
	    s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
	    s/\$LANG/$lang/g;
   	    s/\$VINYL{'news'}/$string/g;
	    s/\$VINYL{'search'}//g;
	    print $_;	
     }
close (FILE);

thanks guys


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

Date: Thu, 09 Jun 2005 05:10:59 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: unitialized value error
Message-Id: <DbQpe.52214$9A2.21583@edtnps89>

Alexandre Jaquet wrote:
> 
> I can't figure why I'm getting this error with my code.
> 
> I've initialized all my var at the begining of my script
> 
> 
> but righ here :  s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
> I got error : Use of unitialized variable in substitution iterator
> 
> simple test script :
> 
> #!perl -w
> use strict;
> 
> my $lang, my $CGISESSID,
> my $LANG, my %VINYL, my %SESSION,  my %SERVER,
> my %ERROR,
> my %PAYPALL, my %WISHLIST;

$ perl -MO=Deparse,-p -e'
my $lang, my $CGISESSID,
my $LANG, my %VINYL, my %SESSION,  my %SERVER,
my %ERROR,
my %PAYPALL, my %WISHLIST;
'
my($lang, $CGISESSID, $LANG, %VINYL, %SESSION, %SERVER, %ERROR, %PAYPALL, 
%WISHLIST);
-e syntax OK


> %WISHLIST = ();
> %PAYPALL = ();
> %ERROR = ();
> $LANG = "";
> %VINYL = ();
> %SESSION = ();
> %SERVER = ();

This is equivalent to your eleven previous lines:

my ( $LANG, $lang, $CGISESSID, %VINYL, %SESSION, %SERVER, %ERROR, %PAYPALL, 
%WISHLIST ) = '';


> #should test for non %00 url encoding ...
> 
> my $dir = "C:/indigoperl/apache/htdocs/recordz/";
> open (FILE, "<$dir/main.html") or die "cannot open file $dir/main.html";
> my $string = "simple test";
>     while (<FILE>) {   
>         s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;

The hash %SERVER is empty so perl is complaining.

         s/\$LABEL{'([\w]+)'}/ exists $SERVER{$1} ? $SERVER{$1} : $1 /eg;


>         s/\$LANG/$lang/g;
>           s/\$VINYL{'news'}/$string/g;
>         s/\$VINYL{'search'}//g;
>         print $_;   
>     }
> close (FILE);
> 
> thanks guys



John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 09 Jun 2005 07:27:23 +0200
From: Alexandre Jaquet <alexj@freesurf.ch>
Subject: Re: unitialized value error
Message-Id: <42a7d340$0$1155$5402220f@news.sunrise.ch>

John W. Krahn a écrit :
> Alexandre Jaquet wrote:
> 
>>
>> I can't figure why I'm getting this error with my code.
>>
>> I've initialized all my var at the begining of my script
>>
>>
>> but righ here :  s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
>> I got error : Use of unitialized variable in substitution iterator
>>
>> simple test script :
>>
>> #!perl -w
>> use strict;
>>
>> my $lang, my $CGISESSID,
>> my $LANG, my %VINYL, my %SESSION,  my %SERVER,
>> my %ERROR,
>> my %PAYPALL, my %WISHLIST;
> 
> 
> $ perl -MO=Deparse,-p -e'
> my $lang, my $CGISESSID,
> my $LANG, my %VINYL, my %SESSION,  my %SERVER,
> my %ERROR,
> my %PAYPALL, my %WISHLIST;
> '
> my($lang, $CGISESSID, $LANG, %VINYL, %SESSION, %SERVER, %ERROR, 
> %PAYPALL, %WISHLIST);
> -e syntax OK
> 
> 
>> %WISHLIST = ();
>> %PAYPALL = ();
>> %ERROR = ();
>> $LANG = "";
>> %VINYL = ();
>> %SESSION = ();
>> %SERVER = ();
> 
> 
> This is equivalent to your eleven previous lines:
> 
> my ( $LANG, $lang, $CGISESSID, %VINYL, %SESSION, %SERVER, %ERROR, 
> %PAYPALL, %WISHLIST ) = '';
> 
> 
>> #should test for non %00 url encoding ...
>>
>> my $dir = "C:/indigoperl/apache/htdocs/recordz/";
>> open (FILE, "<$dir/main.html") or die "cannot open file $dir/main.html";
>> my $string = "simple test";
>>     while (<FILE>) {           s/\$LABEL{'([\w]+)'}/$SERVER{$1}/g;
> 
> 
> The hash %SERVER is empty so perl is complaining.
> 
>         s/\$LABEL{'([\w]+)'}/ exists $SERVER{$1} ? $SERVER{$1} : $1 /eg;
> 
> 
>>         s/\$LANG/$lang/g;
>>           s/\$VINYL{'news'}/$string/g;
>>         s/\$VINYL{'search'}//g;
>>         print $_;       }
>> close (FILE);
>>
>> thanks guys
> 
> 
> 
> 
> John

Many thanks John


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

Date: Thu, 09 Jun 2005 07:35:46 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: unitialized value error
Message-Id: <3gq2pdFdoge2U1@individual.net>

John W. Krahn wrote:
> The hash %SERVER is empty so perl is complaining.
> 
>         s/\$LABEL{'([\w]+)'}/ exists $SERVER{$1} ? $SERVER{$1} : $1 /eg;

Suppose you mean:

     s/\$LABEL{'([\w]+)'}/ defined $SERVER{$1} ? $SERVER{$1} : $1 /eg;
--------------------------^^^^^^^

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


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

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


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