[19873] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2068 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 5 06:06:18 2001

Date: Mon, 5 Nov 2001 03:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1004958310-v10-i2068@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 5 Nov 2001     Volume: 10 Number: 2068

Today's topics:
    Re: .cgi program (Ralph Snart)
    Re: Adding Null Values into a Tied HashRef (E. Moore)
    Re: ASCII and portability <pne-news-20011105@newton.digitalspace.net>
    Re: ASCII and portability <joachim.ziegler@gmx.de>
    Re: Can I use "grep" to search files having common exte (Per Strömgren)
        color problem in perl... <fail006@hotmail.com>
    Re: Failed scripts leave Perl behind <perl@omnibus-systems.net>
    Re: Failed scripts leave Perl behind (Ralph Snart)
        Getting Binary / Unicode data into ADO with Perlscript (Leo Parker)
    Re: HTTP Proxy Module (Rafael Garcia-Suarez)
        One for the Perl Wizards... (mario)
        one question about CGI! (hugh1)
    Re: one question about CGI! <nobody@nowhere.com>
        Perl Module problem <Anthony.Heuveline@wanadoo.fr>
    Re: Perl Module problem (Anno Siegel)
    Re: pervent multiple instances of a server <goldbb2@earthlink.net>
    Re: pervent multiple instances of a server <uri@stemsystems.com>
        Question on File uploading. (Jason Kelley)
        reading and writing with perl CGI to client machines?  <hugo@fractalgraphics.com.au>
    Re: Regexp for email address <goldbb2@earthlink.net>
    Re: Retrieving Perl variables from C <pne-news-20011105@newton.digitalspace.net>
        tail -f <glodalec@yahoo.com>
    Re: tail -f <wuerz@yahoo.com>
    Re: Useless use of private hash in void context <goldbb2@earthlink.net>
    Re: what means about "e" : $name=~ s/.../.../egi (hugh1)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 05 Nov 2001 04:48:50 GMT
From: snart@nospam.com (Ralph Snart)
Subject: Re: .cgi program
Message-Id: <slrn9uc6hn.2122.snart@cluttered.com>

On Sun, 4 Nov 2001 13:45:45 -0600, John Smith <creafin1998@yahoo.com> wrote:
>I'm not getting any error messages from the server log that I have access to
>on any of these 500 server errors I get through my browser.

try adding this line to the top:

use CGI::Carp 'fatalsToBrowser';

this will send the message that is causing the 500 error to
your web browser.

-rs-


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

Date: 4 Nov 2001 20:51:33 -0800
From: emoore@cofs.net (E. Moore)
Subject: Re: Adding Null Values into a Tied HashRef
Message-Id: <f024c24d.0111042051.6d1f91f1@posting.google.com>

> You mean a tied hash via a reference.
Yes - thanks for correcting me.

> That is up to the implementor of the tied hash.

OK.

> That's kinda the whole point of tied things - you can use the same
> syntax as Perl's built-in types but roll your own semantics.
> 
> I am unable to reproduce this bug.

Try this.  (The HTML, "test.htm" is below the __END__).  

Bug?
$in->{empty_garbage} = ''; won't take the empty string.

Thanks, Eric.

#!/usr/local/bin/perl -w

use strict;
use CGI qw/header param/;
my $q   =   new CGI;
my $in  = $q->Vars;

$in->{plain_garbage} = "It's plain.";
$in->{empty_garbage} = '';
$in->{zero_garbage} = 0;
$in->{undef_garbage} = undef;
$in->{garbage_results} = 'After submission the text boxes should
contain:<br>plain = "It\'s plain,<br>empty =  ,<br>zero = 0,<br>undef
= {{undef_garbage}}.';

&PrintHTML($in);
exit;


sub PrintHTML()
{
    my $in    =  shift;
   	my( $html, $key, $value );
    open( FILE, "</your_directory/html/test.htm" ); 
    while( <FILE> )
    {
        while( ( $key, $value )  = each ( %$in ) ){
             s/{{$key}}/$value/gm;
            }
        $html .= $_;
    }
    close( FILE );
    print $q->header();
    print $html;      
}

__END__

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
 "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>test.htm</title>
</head>
<body>
<form action="http://yourdomain/cgi-bin/test.cgi" method=post>
<p>Don't enter anything in the text boxes</p>
<br>
<p>Plain: <input type=text name="plain_garbage"
value="{{plain_garbage}}" size=20 maxlength=20></p>
<p>Empty: <input type=text name="empty_garbage"
value="{{empty_garbage}}" size=20 maxlength=20></p>
<p>Zero: <input type=text name="zero_garbage" value="{{zero_garbage}}"
size=20 maxlength=20></p>
<p>Undef: <input type=text name="undef_garbage"
value="{{undef_garbage}}" size=20 maxlength=20></p>
<br>
<p>{{garbage_results}}</p>
<p><input type=submit name=submit value="submit"></p>
</form>
</body>
</html>


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

Date: Mon, 05 Nov 2001 09:25:37 +0100
From: Philip Newton <pne-news-20011105@newton.digitalspace.net>
Subject: Re: ASCII and portability
Message-Id: <39hcutchcp2oeigmmc6jtc4rk79uhqcqme@4ax.com>

On Sun, 4 Nov 2001 11:43:14 +0100, "Alan J. Flavell"
<flavell@mail.cern.ch> wrote:

> On Nov 4, Joachim Ziegler inscribed on the eternal scroll:
> 
> > this means, that if i write something like
> >
> > print "hello world\n";
> >
> > does ist print 'hello world' on an EBCDIC machine?
> 
> Ill-formed question.  Are you asking if it prints the ASCII string
> which you quoted there?  Clearly not, otherwise it wouldn't work: you
> want to supply program scripts in EBCDIC, and get the answer text in
> EBCDIC - that's what being an "EBCDIC machine" is about.
> 
> But if you want to talk Sockets to an ASCII-based peer, then you want
> a different answer.

Or if he writes his Perl script on an ASCII machine, and transfers it to
an EBCDIC machine without conversion. In which case it simply wouldn't
run as the code points of printable ASCII characters are not, AFAIK,
code points of printable EBCDIC characters.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Mon, 5 Nov 2001 10:38:31 +0100
From: Joachim Ziegler <joachim.ziegler@gmx.de>
Subject: Re: ASCII and portability
Message-Id: <9s5mtv$10m91b$1@ID-107292.news.dfncis.de>

Philip Newton wrote:


> Or if he writes his Perl script on an ASCII machine, and transfers it to
> an EBCDIC machine without conversion. In which case it simply wouldn't
> run as the code points of printable ASCII characters are not, AFAIK,
> code points of printable EBCDIC characters.

thank you, that's what i wanted to know.


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

Date: Mon, 05 Nov 2001 10:27:43 GMT
From: Per.Stromgren@ein.obliterate.ericsson.se (Per Strömgren)
Subject: Re: Can I use "grep" to search files having common extension(e.g. *.c) recursively in a directory?
Message-Id: <9s5o9b$i3c$1@newstoo.ericsson.se>

"dh" <hunter@nortelnetworks.com> wrote:

>grep -i pattern *.c

This is correct ...

>or over directories:
>find . -name *.c | xargs grep pattern

 ... but this won't work. The shell is (*) expanding
the asterisk before find gets it. It should be shielded by using
single quotes, as in:
find . -name '*.c' | xargs grep pattern
or a backslash:
find . -name \*.c | xargs grep pattern

(Logan gave a correct solution in another answer.)

(*) if not told by an suitable command to the shell

Per.

>dave


>"xin" <shenxin@sympatico.ca> wrote in message
>news:bneE7.36434$az4.2951251@news20.bellglobal.com...
>> grep have a option "-r", but the input is supposed to be  a path name. Is
>> there a way to limit the search scope to *.c files(or with any other
>> extensions)  under the path?
>>
>>






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

Date: Mon, 5 Nov 2001 23:32:23 +1300
From: "fail006" <fail006@hotmail.com>
Subject: color problem in perl...
Message-Id: <9s5pfh$vuc$1@lust.ihug.co.nz>

Hi,
I am trying to print colored text in perl, on win98 platform. Here the
script that in copied of the web and tried ruuning it to see if it works

 use Term::ANSIColor;
    print color 'bold blue';
    print "This text is bold blue.\n";
    print color 'reset';
    print "This text is normal.\n";
    print colored ("Yellow on magenta.\n", 'yellow on_magenta');
    print "This text is normal.\n";
    print colored ['yellow on_magenta'], "Yellow on magenta.\n";

here is the output from the msdos window...this is not right..what else do i
need to do..

This text is bold blue.
This text is normal.
Yellow on magenta.
This text is normal.
Yellow on magenta.


How do i print color????

Thanks







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

Date: Sun, 04 Nov 2001 22:34:51 -0500
From: Ken <perl@omnibus-systems.net>
Subject: Re: Failed scripts leave Perl behind
Message-Id: <i42cutcqmfifjh2mpdue7rqifj3hgi6j13@4ax.com>

Thanks for your thoughts. Although I have this urge to drop Perl and
go to PHP, Python, or even VBScript I suspect all of these languages
may suffer the same fate. Any script is activated when its URL is
touched. But that touch lasts only a momnet. Its just not possible to
tell when a user has lost interest. What if I purposely put my Perl
script in a forever loop (must send this to Larry Wall, if you have
for, foreach, then why not forever). I could write a Perl script to
scan the running services to decide if one has been running too long.
But then it would probably kill itself. 

Regards,

Ken Fogel
Dawson College
Montreal, Canada





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

Date: 05 Nov 2001 05:08:28 GMT
From: snart@nospam.com (Ralph Snart)
Subject: Re: Failed scripts leave Perl behind
Message-Id: <slrn9uc7mi.2122.snart@cluttered.com>

On Sun, 04 Nov 2001 22:34:51 -0500, Ken <perl@omnibus-systems.net> wrote:
>Thanks for your thoughts. Although I have this urge to drop Perl and
>go to PHP, Python, or even VBScript I suspect all of these languages
>may suffer the same fate. Any script is activated when its URL is
>touched. But that touch lasts only a momnet. Its just not possible to
>tell when a user has lost interest.

apache kills the perl script when you leave the page in your browser.

at least, it does for me.

just tested with apache 1.3.22, perl 5.6.1, on freebsd 4.  visited
using internet explorer from win2k.


here is my test script:

#!/usr/bin/perl

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

-rs-


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

Date: 4 Nov 2001 23:04:49 -0800
From: onthegoleo@hotmail.com (Leo Parker)
Subject: Getting Binary / Unicode data into ADO with Perlscript
Message-Id: <3c73b13.0111042304.7ca9db6d@posting.google.com>

I don't have a question, just an answer.  I just spent several days
figuring out this problem, so I thought I'd share the answer with the
world, since I can't find any mention to this issue in the newsgroups
up to now.

The problem I've been trying to solve is pretty simple: I have a form
that accepts unicode data (encoded as UTF8) as input, and I'm trying
to get that input into a table in SQL Server using ASP Perlscript, and
ADO.  Sounds like it should be easy, eh?  Nope.  I'll include the
basic source of the program that solves this problem:

The problem is that Win32 and OLE use unicode internally, and
perlscript doesn't.  So whenever a perl string gets converted to a
Variant BSTR for use by Win32, perlscript automatically puts 0x00's
between each byte to make your ascii data work as unicode.  To get
around this, you need to make a variant by hand in this special magic
way that lets you get your binary data in cleanly.

I hope this helps anybody else who might be trying to do
internationalized web programming using Perlscript on an otherwise all
microsoft platform.

-Leo

use Win32::OLE::Variant;
use Unicode::String;

#
# Gather input.  I'm using a $query variable like CGI.pm
#

$id = $query->param('id'); 
$utf8 = $query->param('NOTE');
$ucs2= Unicode::String::utf8($utf8);  # Convert utf8 to real unicode
$sql = "update FORMTABLE set NOTE=? where id=$id";

#
# ADO setup crap...
#

my $cmd = $Server->CreateObject("ADODB.Command");
$cmd->{CommandText} = $sql;
$cmd->{ActiveConnection} = $dbconnection;  # Get this elsewhere
# Here 202 is adVarWChar, and 1 is adInputParam.
my $param = $cmd->CreateParameter('NOTE', 202, 1, length($ucs2) );
$cmd->Parameters->Append( $param);

# Here's the key.  This is the only way to get binary data into
# Win32::OLE from perl.  Otherwise, it assumes your string is
# an ascii string, and inserts 0's in between each byte when it
# converts it to unicode internally.  Boy I hope Perl 5.6
# has a better answer for this.
my $variant = Win32::OLE::Variant->new(VT_UI1, $ucs2);

$cmd->Parameters->Item(0)->{value} = $variant;

# Run it!
my $adorecset = $cmd->Execute;


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

Date: 5 Nov 2001 09:24:27 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: HTTP Proxy Module
Message-Id: <slrn9ucmn5.vbh.rgarciasuarez@rafael.kazibao.net>

Wyzelli wrote in comp.lang.perl.misc:
> 
> "OSx" <femello@mac.com> wrote in message
> news:omkF7.4829$MI.1873113@typhoon.ne.mediaone.net...
> > Hi,
> >
> > I saw the SOCKS module on CPAN and I was wondering if there's a HTTP proxy
> > module..
> 
> Not a module as such, but you might find this interesting:-
> 
> http://www.stonehenge.com/merlyn/WebTechniques/col11.html

Or maybe also http://rgarciasuarez.free.fr/perl/biscuit.html
(a more elaborated example, based on the previous one)

-- 
Rafael Garcia-Suarez


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

Date: 4 Nov 2001 21:30:11 -0800
From: mgaffi@acxiom.com (mario)
Subject: One for the Perl Wizards...
Message-Id: <9b89f882.0111042130.8f4d047@posting.google.com>

In the following piece of code, any idea why the index() call, which
is outside the while loop, slows down the while loop? For some reason,
using the index() function decreases program performance, even if its
called only once outside any looping block...


use constant VERBOSE => scalar 500000;
open(DATA, "Version1-1/IB.dat");
open(OUTPUT_FILE, ">test.dat");
$tm = `date`; chomp($tm); print STDERR "[$tm] $. records.\n";
$s = index($tm, 0, 3);
while (<DATA>)
{
    print OUTPUT_FILE;
    next unless ($. % VERBOSE == 0);
    $tm = `date`; chomp($tm); print STDERR "[$tm] $. records.\n";
} 

Thanks, Mario


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

Date: 5 Nov 2001 00:58:39 -0800
From: weiwe1@yeah.net (hugh1)
Subject: one question about CGI!
Message-Id: <7dcf30ba.0111050058.4a01e44e@posting.google.com>

thanx!

  my english is poor! i try my best to let you know my question!

  now i have a tast to change my company's some CGI program.
  
  http://localhost/cgi-bin/charge.cgi........... 
 one cgi-program "charge.cgi" function is add user's money. for
example: on the web netscape, i save my account $100, and the CGI
call charge.cgi to do it.and the web refresh, have not result 
stat output! but i check my account ,i find the action is done right.
i want to add the result stat output!
  if charge.cgi is do ok! it is display "ok" on new web page.
  else display "wrong" web page!

 the charge.cgi maybe C compiled program. how can i do??
 thanx for your help!
  
 and i can not know which knowledge i should to learn !


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

Date: Mon, 5 Nov 2001 20:59:53 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: one question about CGI!
Message-Id: <5guF7.82742$g8.70852@newsfeeds.bigpond.com>

"hugh1" <weiwe1@yeah.net> wrote in message
news:7dcf30ba.0111050058.4a01e44e@posting.google.com...
>  the charge.cgi maybe C compiled program. how can i do??
>  thanx for your help!
>

comp.lang.perl.misc is not the place to ask questions about C.
See
http://directory.google.com/Top/Computers/Programming/Languages/C/Tutorials/

gtoomey




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

Date: Mon, 5 Nov 2001 11:44:22 +0100
From: "Anthony Heuveline" <Anthony.Heuveline@wanadoo.fr>
Subject: Perl Module problem
Message-Id: <9s5qfk$qs0$1@wanadoo.fr>

Hi,

I am working on a server where all Perl core modules are installed. The
problem is that I want to use some functions that are not included in these
core modules. I have already installed CGI.pm and DBI.pm, uploading these
two files on the server, and it works.

I also need to use File::Basename and File::Copy modules but I didn't find
them, even on CPAN. As I am a newbie in perl and in server handling, could
you help me to find the needed files?

Thank you.

Anthony.




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

Date: 5 Nov 2001 11:03:26 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl Module problem
Message-Id: <9s5rlu$cos$1@mamenchi.zrz.TU-Berlin.DE>

According to Anthony Heuveline <Anthony.Heuveline@wanadoo.fr>:
> Hi,
> 
> I am working on a server where all Perl core modules are installed. The
> problem is that I want to use some functions that are not included in these
> core modules. I have already installed CGI.pm and DBI.pm, uploading these
> two files on the server, and it works.
> 
> I also need to use File::Basename and File::Copy modules but I didn't find
> them, even on CPAN. As I am a newbie in perl and in server handling, could
> you help me to find the needed files?

They are there, I assure you.  Try a CPAN search, starting for instance
at http://theoryx5.uwinnipeg.ca/CPAN/cpan-search.htm

Anno


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

Date: Mon, 05 Nov 2001 03:17:52 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: pervent multiple instances of a server
Message-Id: <3BE64B30.C8C348BD@earthlink.net>

Richard J. Rauenzahn wrote:
> 
> Benjamin Goldberg <goldbb2@earthlink.net> writes:
> >6.  Count, using stat, the number of "links" to the program file.  It
> >should be 2: one directory entry, one open file [perl holding the
> >script open]:
> >       die "Program is already running\n"
> >               if (stat $0)[3] > 2;
> >or:
> >       die "Program is already running\n"
> >               if (stat DATA)[3] > 2;
> 
> Huh?!?  Run that by me again!
> 
> (In other words, I don't believe that works.  At least not on my *nix
> boxes!)

You are right, I was wrong.

I *though* that nlink was a kind of reference count -- directory entries
plus open filedescriptors -- for the file, with the property that when
the number goes to zero, the file is deleted.

The data *is* available by parsing the output of either /sbin/fuser or
/usr/sbin/lsof ... but since parsing the output of external programs,
is, in general, nonportable [not to mention, you might not even have
either of program], I guess my idea isn't exactly a good one.

-- 
Klein bottle for rent - inquire within.


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

Date: Mon, 05 Nov 2001 08:20:43 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: pervent multiple instances of a server
Message-Id: <x7wv15vd9t.fsf@home.sysarch.com>

>>>>> "BG" == Benjamin Goldberg <goldbb2@earthlink.net> writes:

  BG> Richard J. Rauenzahn wrote:
  >> 
  >> Benjamin Goldberg <goldbb2@earthlink.net> writes:
  >> >6.  Count, using stat, the number of "links" to the program file.  It
  >> >should be 2: one directory entry, one open file [perl holding the
  >> >script open]:
  >> >       die "Program is already running\n"
  >> >               if (stat $0)[3] > 2;
  >> >or:
  >> >       die "Program is already running\n"
  >> >               if (stat DATA)[3] > 2;
  >> 
  >> Huh?!?  Run that by me again!
  >> 
  >> (In other words, I don't believe that works.  At least not on my *nix
  >> boxes!)

  BG> You are right, I was wrong.

  BG> I *though* that nlink was a kind of reference count -- directory entries
  BG> plus open filedescriptors -- for the file, with the property that when
  BG> the number goes to zero, the file is deleted.

you are confusing the kernel inode (vnode or whatever it is called) with
the file inode. they are not directly related but they have a common past.

  BG> The data *is* available by parsing the output of either /sbin/fuser or
  BG> /usr/sbin/lsof ... but since parsing the output of external programs,
  BG> is, in general, nonportable [not to mention, you might not even have
  BG> either of program], I guess my idea isn't exactly a good one.

and those programs can be very slow too.

a simple lock will do or a server address bind which atomic will work
too. there are other ways to guarantee your program is not running a
second copy.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 5 Nov 2001 01:33:10 -0800
From: loophole64@home.com (Jason Kelley)
Subject: Question on File uploading.
Message-Id: <bc7d7750.0111050133.170d188b@posting.google.com>

I'm trying to upload a file through a form that several input fields,
including the file input. I don't want to use CGI.pm for efficiency
reasons. If I have the following inputs on my form in this order:

<INPUT size="20" type="text" name="team1">
<INPUT size="20" type="text" name="team2">
<INPUT size="20" type="text" name="map">
<INPUT TYPE="file" NAME="repfile" size="25">

And I use the following code to grab the form data:

# Get the input from the form.
binmode (STDIN);
read (STDIN, $upload_data, $ENV{'CONTENT_LENGTH'});

What is the format of $upload_data? I would expect it to be something
like:

team1=clodhoppers&team2=boppy&map=firefields&FileInfoHere...

But that doesn't seem to be the case. Does the file info come first?
And where exactly is the file name in relation to the file data? Any
info to help me understand this would be appreciated. Thanks.

-Jason


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

Date: Mon, 05 Nov 2001 15:59:35 +0800
From: hugo <hugo@fractalgraphics.com.au>
Subject: reading and writing with perl CGI to client machines? 
Message-Id: <3BE646E7.8E0E626B@fractalgraphics.com.au>

Hi 

I have a question about something that, for security reasons, possibly
can't be done, and yet would be very useful to me. 

I want to read in a file with a cgi script, double space it, then write
an output file back to the place the input file came from. Later on I
want to perform more operations on the double-spaced file. 

If I have an input file on our server e.g. in /tmp/text.txt, I can read
in the input file, and the output file is made, double spaced and all. 
No problem. 

However, (and I know this can normally not be done for sound security
reasons) I would like a file to be uploaded from a client (e.g. a
windows machine), and the output file being written away in the same
directory of the client machine as well. So rather than getting my input
file from /tmp/test.txt, I would like to get if from, for example,
C:\mydirectory\test.txt and write the output file to that directory as
well. 
Totally impossible? 

Note that when I try to upload from my local machine, the file is not
found (as expected, as my C drive is not available to the server). So in
short, my questions are: 

(1) How do I get the server to read in the file from the client
directory and (2) how do I allow the server to write an output file back
to the same directory on the client machine.   

Here is my code so far (note that $datafile is obtained by performing a
$query->param on the contents of an upload field and that the
$double_spaced_file is a simple conversion changing the extension from
whatever it was to *.out. The strings for $datafile and
$double_spaced_file include the full path.)  

 open(INFILE, "$datafile")|| die "Could not open $datafile:
$!\nStopped";
     open(OUTFILE, ">$double_spaced_file") || die "Could not open
$double_spaced_file: $!\nStopped"; 
   while (<INFILE>) {
	print OUTFILE "$_\n";
       	}
   close (INFILE);
   close(OUTFILE);

Any help will be greatly appreciated. 

Thanks

Hugo 
 
-- 
Dr Hugo Bouckaert
R&D Support Engineer, Fractal Graphics 
57 Havelock Street, West Perth 6005
Western Australia 6009
Tel: +618 9211 6000 Fax: +618 9226 1299
Email:hugo@fractalgraphics.com.au
Web: http://www.fractalgraphics.com.au


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

Date: Mon, 05 Nov 2001 03:46:50 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Regexp for email address
Message-Id: <3BE651FA.E5AC27CE@earthlink.net>

Glenn White wrote:
> 
> Ilmari Karonen <iltzu@sci.invalid> wrote in
> <1004656173.18445@itz.pp.sci.fi>:
> 
> >>$line = join ';', grep { !/\@/ && s/$/\@tester.com/ }
> >>    split /;/, $line;
> >
> >This works just fine, except that you need to make the grep block
> >always evaluate to a true value.  A simple change accomplishes this:
> >
> > $line = join ';', grep { /\@/ || s/$/\@tester.com/ } split /;/,
> >     $line;
> >
> >But I'd still prefer the explicit version using map():
> >
> > $line = join ';', map { /\@/ ? $_ : "$_\@tester.com" } split /;/,
> >     $line;
> >
> 
> Now that you pointed out the "and" and "or" difference, it makes
> perfect sense.
> 
> As a copout, I ended up doing the following:
> 
> @fields = split(/\;/, $line);     # Seperate email addresses
> while ($fields[$i]) {
>   if (not($fields[$i] =~ /\@/)) {
>     $fields[$i] =~ s/$fields[$i]/$fields[$i]$default_address/;
>   }
> $i = $i +1;
> }
> $line = join(';',@fields);        # Join email addr into one line
> 
> It is somewhat non-perlish... but it was very easy for my level of
> skill.

It's quite nonperlish...

Here's a slightly more perlish way of doing that:
my @fields = split /;/, $line;
foreach( @fields ) {
    $_ .= $default_address unless /\@/;
}
$line = join ';', @fields;

When looping over an array and changing items, use foreach().
If you want to append to a string, you should usually do it explicitly,
with . or .= or with qq interpolation, not via s///.

The join/map/split solution suggested by Ilmari is preferable to my
split,foreach,join solution because it doesn't create a temporary array.
On the other hand, a foreach-type solution is more readable.

Here's another perlish way:
$line =~ s/((?:^|;)[^;@]*)(?=;|$)/$1$default_address/g;

After all, if you're going to bother to use s///, you might as well do
it for the whole line at once.

Anyone up for a game of perl golf on this?  [besides changing that (?:)
to just a ()]

-- 
Klein bottle for rent - inquire within.


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

Date: Mon, 05 Nov 2001 09:25:38 +0100
From: Philip Newton <pne-news-20011105@newton.digitalspace.net>
Subject: Re: Retrieving Perl variables from C
Message-Id: <fkhcut8v1aiv6gujokug794v8ckap4h0jd@4ax.com>

On 4 Nov 2001 14:03:49 -0800, grday@afterlife.ncsc.mil (Gary R. Day)
wrote:

> When I try to compile the C program that appears below, which I copied
> from the book "Programming PERL," I get the messages that follow.

I presume you mean _Programming Perl_ (the example is on pp. 541f. in
the third edition). There is no PERL.

> perlex.c:10: warning: assignment makes pointer from integer without a
> cast

This comes from a typo:

>     10	  my_perl = perlalloc();

Read the example again and count the number of underscores in
'perl_alloc()'. Your C compiler assumed that perlalloc() is a function
returning an int, since it has no prototype (unlike perl_alloc, which
would be prototyped in one of Perl's headers).

I can't help you about the other errors. However, this line:

> gcc -c -I/interix/usr/lib/perl5/opennt/5.00305/CORE perlex.c

appears to indicate that you have a rather old perl (5.003_05). Or was
that a typo for "5.00503"? If so, please don't re-type; rather, use copy
and paste. If not, could you upgrade your Perl to at least 5.005_03, or
optionally 5.6.1?

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Mon, 5 Nov 2001 06:09:21 +0100
From: Marvin <glodalec@yahoo.com>
Subject: tail -f
Message-Id: <MPG.16503d6d9f0ce078989717@news.siol.net>

Hi !

Can someone show me, how can I open file and track any appendicies in it 
(like tail -f on unix does)

while (<MYFILE>)
{
}

reads the whole file, and then exits, so I need another while accross 
it. Is there any other way ?


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

Date: 05 Nov 2001 00:12:27 -0500
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: tail -f
Message-Id: <m3g07tyf5w.fsf@DCCMBX01.njitdm.campus.njit.edu>

Marvin <glodalec@yahoo.com> writes:

> Can someone show me, how can I open file and track any appendicies in it 
> (like tail -f on unix does)

perldoc -q tail
        `How do I do a "tail -f" in perl?'

-- 
$_="\n,rekcah egnufeB rehtona tsuJ";#v1<?>g\:pv-<5<
s s\S+(?:B)sunpack'u',q q$;')E4qsee;#>60#^<(v!<)g6<
print scalar reverse,$@ unless m,[+;#]55,;m:_,:#^1<


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

Date: Mon, 05 Nov 2001 04:16:54 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Useless use of private hash in void context
Message-Id: <3BE65906.C6F32416@earthlink.net>

Mike Wangu wrote:
> 
> Clinton,
> 
> Thank you for your prompt response. Your assessment is right on the
> money. This line was a throwback from a previous version of my module,
> and was not modified appropriately (at all).
> 
> What I was attempting to do in the new version, combine two hashrefs
> into one, is better as:
> 
> $projtree->{$spdata[0]} = {
>         %{ $projtree->{$spdata[0]} },
>         %{ $self->gettree($spdata[3], $recurse) }
> };

An even better way of combining them [considering you are combining a
and b and storing into a] would be:

my $gettree = $self->gettree($spdata[3], $recurse);
@{$$projtree{$spdata[0]}}{ keys %$gettree } = values %$gettree;

I would like to mention that if you do "map { foo } @bar" doesn't do
anything if @bar is empty, so you don't need the "if @bar" qualifyer.

foreach is more readable than map, particularly if you are doing it
purely for side effects, not the return value.

I don't see in your code anything adding to @subproj, so there's no
point in having that while loop.

So I guess the code sorta reduces to:

my $projtree = $self->_addnode({}, [ $self->projectattr($croot) ]);

foreach my $spdata ( $self->searchpr($croot) ) {
    my ($foo, $bar) = @$spdata[0,3];
    $$projtree{$foo} =
        $self->_addnode($$projtree{$bar}, $spdata);
    foreach my $ignore ( $recurse ? $self->searchpr($bar) : () ) {
        my %gettree = $self->gettree($bar, 1);
        @{$$projtree{$foo}}{ keys %gettree } = values %gettree;
    }
}

NB: This code is untested.

-- 
Klein bottle for rent - inquire within.


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

Date: 4 Nov 2001 19:01:23 -0800
From: weiwe1@yeah.net (hugh1)
Subject: Re: what means about "e" : $name=~ s/.../.../egi
Message-Id: <7dcf30ba.0111041901.6d95c7c9@posting.google.com>

i like your "just another perl hacker !!!"
it is great!


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

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


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