[18417] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 585 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 29 14:16:15 2001

Date: Thu, 29 Mar 2001 11:15:44 -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: <985893343-v10-i585@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 29 Mar 2001     Volume: 10 Number: 585

Today's topics:
        peculiar regex problem <kca@po.cwru.edu>
    Re: peculiar regex problem <bmb@ginger.libs.uga.edu>
    Re: peculiar regex problem <wyzelli@yahoo.com>
        Perl / CGI Editors <Sh0t2bts@hotmail.com>
    Re: Perl / CGI Editors <djmarcus@ex-pressnet.com>
        Perl Mail Headers director@internetsubmit.net
    Re: Perl wrapper for Java program (Abigail)
    Re: printing colons (Gary E. Ansok)
    Re: Q: Active Perl redistributable MINIMUM? (Richard Williams)
    Re: Question about File::Find module? (Abigail)
    Re: Question about File::Find module? <shah@typhoon.xnet.com>
    Re: Question about File::Find module? <shah@typhoon.xnet.com>
    Re: Question about File::Find module? <ddunham@redwood.taos.com>
    Re: Re: passing strings containing variables to subs <kimmfc@mydeja.com>
    Re: Re: passing strings containing variables to subs (Tad McClellan)
    Re: Read and write a hash of arrays ? <bigrich318@yahoo.com>
    Re: Regex question <uri@sysarch.com>
    Re: Regex question (Charles DeRykus)
    Re: regexp with multiple \n? <kstep@pepsdesign.com>
    Re: regexp with multiple \n? <leggett@americasm01.nt.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 28 Mar 2001 16:56:07 -0800
From: Kevin Connor Arpe <kca@po.cwru.edu>
Subject: peculiar regex problem
Message-Id: <3AC28827.10AA@po.cwru.edu>

I'm having a problem with what should be the simplest regex.
I want to remove (from a string) all instances of useless HTML tags,
i.e., <tag>whitespace</tag>.

This should be as easy as:

$data =~ s/<[^>]>\s*<\/[^]>//g ;

But it won't work.
I haven't a clue what's wrong.  I tried changing the \s* to \s+ with not
much luck.

Any help would be great.
Do me a favor and bang-me-up at my email'er too?  I can't possibly
shuffle through 4700+ messages on the .misc channel.

Thanks,
Kevin.


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

Date: Wed, 28 Mar 2001 20:16:33 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
To: Kevin Connor Arpe <kca@po.cwru.edu>
Subject: Re: peculiar regex problem
Message-Id: <Pine.A41.4.21.0103282010110.13834-100000@ginger.libs.uga.edu>

[emailed Kevin Connor Arpe directly, too]

On Wed, 28 Mar 2001, Kevin Connor Arpe wrote:
> $data =~ s/<[^>]>\s*<\/[^]>//g ;
> 
> But it won't work.
> I haven't a clue what's wrong.  I tried changing the \s* to \s+ with not
> much luck.

I guess it's not your real code, because it won't compile.  Regardless,
the problem is missing quantifiers:

$data =~ s/<[^>]+>\s*<\/[^>]+>//g ;

> Any help would be great.
> Do me a favor and bang-me-up at my email'er too?  I can't possibly
> shuffle through 4700+ messages on the .misc channel.

Why would you do that?

Brad




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

Date: Thu, 29 Mar 2001 10:55:35 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: peculiar regex problem
Message-Id: <vZvw6.11$US1.3998@vic.nntp.telstra.net>

Emailed as well...

"Kevin Connor Arpe" <kca@po.cwru.edu> wrote in message
news:3AC28827.10AA@po.cwru.edu...
> I'm having a problem with what should be the simplest regex.
> I want to remove (from a string) all instances of useless HTML tags,
> i.e., <tag>whitespace</tag>.
>
> This should be as easy as:
>
> $data =~ s/<[^>]>\s*<\/[^]>//g ;

Perhaps more than one [^>] ?? (before and after...)  Also you want
something in the ending character class more than just the negation...

$data =~ s/<[^>]+>\s*<\/[^>]+>//g;


> But it won't work.
> I haven't a clue what's wrong.  I tried changing the \s* to \s+ with
not
> much luck.

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass
it around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";





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

Date: Wed, 28 Mar 2001 23:22:35 +0100
From: "Ntl World" <Sh0t2bts@hotmail.com>
Subject: Perl / CGI Editors
Message-Id: <Mutw6.26799$pb.270217@news11-gui.server.ntli.net>

Hi All,
I am sure this has been asked loads of times.
I have looked in this news group for answers bit could not find any...

Anyway my question.

I currently do quite a bit of CGI scripting for web pages, I am using a
Program called PFE "I'm sure you would have heard of it"
This is a great program for small scripts where it is easy to keep track but
I am after some thing that will highlight Vars, Sub routines & comments Etc.


Could anyone recommend a program which would do this???

Many Thanks

Mark




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

Date: Wed, 28 Mar 2001 23:05:06 -0500
From: "David J. Marcus" <djmarcus@ex-pressnet.com>
Subject: Re: Perl / CGI Editors
Message-Id: <tc5d3el5930q22@corp.supernews.com>

Hi

I am currently using OptiPerl 3.1 pro (www.xarka.com/optiperl)

I am very impressed with the product and the support. The people at Xarka
have responded to every question I had, including one on a Sunday. The
product will syntax-color your code, support multiple concurrent edits,
support code templates (lets you quickly insert templated code), debugging
(breakpoints, display of variables, etc), run in browser (for CGI testing),
and many other features that I have yet to explore. In short I have found it
to be a great IDE (Integrated Development Environment) for Perl.

-Regards
David


"Ntl World" <Sh0t2bts@hotmail.com> wrote in message
news:Mutw6.26799$pb.270217@news11-gui.server.ntli.net...
> Hi All,
> I am sure this has been asked loads of times.
> I have looked in this news group for answers bit could not find any...
>
> Anyway my question.
>
> I currently do quite a bit of CGI scripting for web pages, I am using a
> Program called PFE "I'm sure you would have heard of it"
> This is a great program for small scripts where it is easy to keep track
but
> I am after some thing that will highlight Vars, Sub routines & comments
Etc.
>
>
> Could anyone recommend a program which would do this???
>
> Many Thanks
>
> Mark
>
>




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

Date: 29 Mar 2001 16:07:50 GMT
From: director@internetsubmit.net
Subject: Perl Mail Headers
Message-Id: <99vmkm$dl0$1@news.netmar.com>


I am trying to use Mail and put in these Headers! Does anyone know how? I am
trying to send an HTML file and have it appear as HTML.

	"Mime-Version: 1.0\n\n";
	"Content-Type: text/html; charset=iso-8859-1\n\n";
              
  

open (MAIL, "|$mailprog -t")
	            || print "Can't start mail program";
		print MAIL "To: $lines\n";
	        print MAIL  "From: $list_mail\n";
		print MAIL  "Subject: $mail_subject\n\n";
print MAIL"\n\n";
                close (MAIL);

Thanks


 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net


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

Date: Thu, 29 Mar 2001 17:14:36 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Perl wrapper for Java program
Message-Id: <slrn9c6rbs.4bl.abigail@tsathoggua.rlyeh.net>

Art Werschulz (agw@smolyak.cs.columbia.edu) wrote on MMDCCLXVII September
MCMXCIII in <URL:news:ylaitkswrzn.fsf@smolyak.cs.columbia.edu>:
"" Hi.
"" 
"" I would like to have a Perl script that's a wrapper for a Java
"" program.  The main reason for this is if the Perl script were
"" suid and the Java classes were non-world-readable, then I would
"" essentially have a Java program that could others could run, but
"" they wouldn't be able to examine the Java classes.
"" 
"" The obvious thing to try is something along the following lines:
"" 
""   #!/usr/bin/perl -T
"" 
""   $ENV{PATH} = "/bin:/usr/bin";
""   $javaProg = "/usr/bin/java MyProg";
""   system($javaProg);
"" 
"" But when I run this, it returns immediately, without prompting (or
"" getting) any input and without producing any output.  This happens for
"" something as simple as a HelloWorld program.

Did you check $! and $? Or the return value of system?

"" Any idea what's going wrong here?  Thanks.

Did you read 'man perlsec'? It's explained there in the first list
of examples.



Abigail
-- 
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
         % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
         BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'


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

Date: 28 Mar 2001 18:22:29 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: printing colons
Message-Id: <99ta55$rf5@gap.cco.caltech.edu>

In article <dwnw6.96$__1.2348@eagle.america.net>,
Ken Gerdes <texasreddog@yahoo.com> wrote:
>I am having some strange trouble printing a colon in a string in Perl.  This
>is the part of my script that is giving me trouble:
>
> # if the file is a java file or jsp, just copy it
>   if($_ =~ /\.jsp|\.java/){
>      $pathtofile = $_;
>      chop($pathtofile);
>      print "\/usr\/local\/bin\/scp webl\@$fromhost\:";
>      #print "$pathtofile\n";
>   } else {
>   }
>
>My output should look like this:
>
>/usr/local/bin/scp webl@bedfellow:/path/to/file
>
>Instead, I am getting this:
>
>:[ken@binkley perl]$ bl@bedfellow
>
>It is putting the colon at the beginning of the line, followed by a prompt,
>then the rest of the stuff!  I don't get this at all!  I tried backslashing
>the colon, putting it on a separate line, etc, but nothing works.  How can I
>get it to print at the end of the statement, as above?

You don't say how $fromhost gets its data loaded, but it sounds like
the string has "\r\n" (carriage-return and new-line) at the end.
You chop() off the "\n", but the \r is still at the end of $fromhost.

To verify what $fromhost contains, do this:
   print "Fromhost is >>$fromhost<<"; 

There's nothing special about printing colons (and there's nothing
special about slashes in a quoted string, so they don't need back-
slashing in your print statement either).  You might also look at
using chomp() instead of chop().

-- Gary Ansok


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

Date: 28 Mar 2001 21:23:11 GMT
From: rdwillia@hgmp.mrc.ac.uk (Richard Williams)
Subject: Re: Q: Active Perl redistributable MINIMUM?
Message-Id: <99tknv$dsn$1@niobium.hgmp.mrc.ac.uk>

In article <3ABFCBFB.D170165C@privacy.nu>,
Jeremy  <jeremyk.remove-this@privacy.nu> wrote:
>Hello, Gurus.
>
>Does anyone know what the absolutely minimal Active Perl installation
>consists of? Assume I use no packages, only the very core perl
>functionality, what do I need to install on a machine in order to be
>able to run it? (The old perl was easy in that respect, while the
>"Active" perl is too Window'ish, takes huge amount of space on disk,
>installs fifty bazillion files, and probably puts something in the
>Registry.) I need to move it quickly though, and nonintrusively in terms
>of machine configuration.

You may want to take a look at Indigostar's build of perl for Windows
(www.indigostar.com). No installation beyond unzipping is required
(there's an optional setup script that just creates shortcuts
and updates your PATH, but it's written in Perl so you can see exactly
what it's doing). With a little experimentation, it ought to be quite easy
to figure out which subset of the distribution is sufficient for your
purposes - I've just run a text processing script that does regex matching
and file I/O using only perl.exe, perl56.dll and strict.pm (well under
700K in total) without problems. Note also that the Activestate license
does not permit re-distribution of their binaries 'outside your 
organization', whereas Indigoperl is freely redistributable.


Richard.



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

Date: Wed, 28 Mar 2001 22:10:17 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Question about File::Find module?
Message-Id: <slrn9c4oa9.9ac.abigail@tsathoggua.rlyeh.net>

Hemant Shah (shah@typhoon.xnet.com) wrote on MMDCCLXVI September MCMXCIII
in <URL:news:99tl6c$j2m$1@flood.xnet.com>:
** While stranded on information super highway Abigail wrote:
** :)
** :)However, having said that, there's no reason to assume one has to
** :)use File::Find to traverse the file system. I've never used File::Find
** :)myself, but I often use find. Which works fine from within Perl:
** 
**    Here is a description of File::Find I found on web:
**    -----cut-------------cut-------------cut-------------cut------
** find() does a recursive subdirectory search of $dir. It calls Wanted()
** once for each file and directory in $dir, including $dir itself. You can
** actually specify a list of directories, and find() will search all of
** them.
**    
** Typically, Wanted() begins by deciding whether it wants to operate on
** the current file. Regular expression matches on $_ do this concisely.
**    -----cut-------------cut-------------cut-------------cut------

Well, I *do* know what File::Find does. I just haven't seen much use
for it. "find" works for me.

** :)    open my $find => "find / -name 'core' \! -fstype nfs -print0 |" or die;
** :)    $/ = "\x00";
** :)    while (<$find>) {...}
** :)    close $find or die;
** 
**     This will still traverse all the file system and reject all the nfs files
**     just like Find:File module.
** 
**     To test it try the following commands:
** 
**     find / -name core ! -fstype nfs -print
** 
**     and now specify all the local file systems and use -xdev option:
** 
**     find / /usr /home -name core -xdev -print
** 
**     The second command will run much faster as it skips the directories
**     on other filesystems.

True, but you should be able to do something with prune.

    find / -name core -print \! -fstype nfs -o -prune

** :)Of course, if you just want to delete the files, no need for the open.
** :)
** :)    system q {find / -name 'core' \! -fstype nfs -exec rm {} \;};
** 
**      Instead of using -exec command try piping into xargs, it will
**      execute much faster. The -exec will execute rm command for each
**      file, but when you pipe it into xargs it will execute rm command
**      for every 1000 files.

You have that many core files on your system that it makes a
significant difference?



Abigail
-- 
perl -wle '$, = " "; sub AUTOLOAD {($AUTOLOAD =~ /::(.*)/) [0];}
           print+Just (), another (), Perl (), Hacker ();'


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

Date: Wed, 28 Mar 2001 21:24:17 +0000 (UTC)
From: Hemant Shah <shah@typhoon.xnet.com>
Subject: Re: Question about File::Find module?
Message-Id: <99tkq1$ipf$1@flood.xnet.com>

While stranded on information super highway nobull@mail.com wrote:
:)Hemant Shah <shah@typhoon.xnet.com> writes:
:)
:)>    find2perl / -type f -name core ! -fstype nfs -print
:)> 
:)>    Will generate following code:
:)> 
:)> ---------cut-------------cut-------------cut-------------cut----
:)> File::Find::find({wanted => \&wanted}, '/');
:)> 
:)> sub wanted {
:)>     my ($dev,$ino,$mode,$nlink,$uid,$gid);
:)> 
:)>     (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
:)>     -f _ &&
:)>     /^core\z/s &&
:)>     ! ($dev >= 0) &&
:)>     print("$name\n");
:)> }
:)> ---------cut-------------cut-------------cut-------------cut----
:)> 
:)> I see 2 problems with the above code:
:)> 
:)> 1) File::Find::find will traverse all the filesystems, the "wanted" function
:)>    decides what to do with the entry. This does not look like a good solution
:)>    for me, because I have a 60GB file system (users home directory) NFS
:)>    mounted across 20 systems, and I do not want 20 systems traversing the file
:)>    system every night.
:)
:)So "prune" when you hit a NFS filesysetem.

   That does not help. Even if I prune on NFS, find function will still
   traverse the whole NFS file system and for every entry I will have to
   prune.

   Here is a description of File::Find I found on web:
   -----cut-------------cut-------------cut-------------cut------
find() does a recursive subdirectory search of $dir. It calls Wanted()
once for each file and directory in $dir, including $dir itself. You can
actually specify a list of directories, and find() will search all of
them.

Typically, Wanted() begins by deciding whether it wants to operate on
the current file. Regular expression matches on $_ do this concisely.
   -----cut-------------cut-------------cut-------------cut------

   Example:

   /     --> local filesystem
   /usr  --> local filesystem
   /apex --> nfs filesystem

   If I execute the above find command, it will traverse /, /usr, and /apex,
   even if I prune in my function (wanted).

   The solution I found was to use find command, and specify the local file
   systems directories on command line and use -xdev option which will not 
   descend directories on other filesystems.

   Example:

   find / /usr -xdev -type f -name core -print

   This will skip /apex directory.



:)

-- 
Hemant Shah                           /"\  ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com       \ /  --------------------- 
                                       X     against HTML mail
TO REPLY, REMOVE NoJunkMail           / \      and postings      
FROM MY E-MAIL ADDRESS.           
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind,                Above opinions are mine only.
it's backed up on tape somewhere.      Others can have their own.


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

Date: Wed, 28 Mar 2001 21:30:52 +0000 (UTC)
From: Hemant Shah <shah@typhoon.xnet.com>
Subject: Re: Question about File::Find module?
Message-Id: <99tl6c$j2m$1@flood.xnet.com>

While stranded on information super highway Abigail wrote:
:)Hemant Shah (shah@typhoon.xnet.com) wrote on MMDCCLXVI September MCMXCIII
:)in <URL:news:99t2ah$7v2$1@flood.xnet.com>:
:)[] 
:)[] I see 2 problems with the above code:
:)[] 
:)[] 1) File::Find::find will traverse all the filesystems, the "wanted" function
:)[]    decides what to do with the entry. This does not look like a good solution
:)[]    for me, because I have a 60GB file system (users home directory) NFS
:)[]    mounted across 20 systems, and I do not want 20 systems traversing the fil
:)[]    system every night.
:)[] 
:)[] 2) Someone else mentioned it in another post that on Solaris 8 the
:)[]    ($dev < 0) test does not work for NFS file systems.
:)[] 
:)[] 
:)[]    I have to run the script on Linux, AIX 4.2.1, AIX 4.3.3, HP-UX 10.2,
:)[]    HP-UX 11.x, Solaris 8.
:)[] 
:)[]    Is there a better solution in perl? Otherwise I am back to using find
:)[]    command and ksh.
:)
:)
:)Well, it's fairly trivial to find out which systems are NFS mounted -
:)"mount" will tell you.
:)
:)However, having said that, there's no reason to assume one has to
:)use File::Find to traverse the file system. I've never used File::Find
:)myself, but I often use find. Which works fine from within Perl:

   Here is a description of File::Find I found on web:
   -----cut-------------cut-------------cut-------------cut------
find() does a recursive subdirectory search of $dir. It calls Wanted()
once for each file and directory in $dir, including $dir itself. You can
actually specify a list of directories, and find() will search all of
them.
   
Typically, Wanted() begins by deciding whether it wants to operate on
the current file. Regular expression matches on $_ do this concisely.
   -----cut-------------cut-------------cut-------------cut------


:)
:)    open my $find => "find / -name 'core' \! -fstype nfs -print0 |" or die;
:)    $/ = "\x00";
:)    while (<$find>) {...}
:)    close $find or die;

    This will still traverse all the file system and reject all the nfs files
    just like Find:File module.

    To test it try the following commands:

    find / -name core ! -fstype nfs -print

    and now specify all the local file systems and use -xdev option:

    find / /usr /home -name core -xdev -print

    The second command will run much faster as it skips the directories
    on other filesystems.


:)
:)Of course, if you just want to delete the files, no need for the open.
:)
:)    system q {find / -name 'core' \! -fstype nfs -exec rm {} \;};

     Instead of using -exec command try piping into xargs, it will
     execute much faster. The -exec will execute rm command for each
     file, but when you pipe it into xargs it will execute rm command
     for every 1000 files.

     system q {find / -name 'core' \! -fstype nfs -print | xargs /bin/rm};
:)
:)If you want to, you could do all the deletes in a single find.
:)
:)Abigail
:)-- 
:)perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
:)             "\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
:)             "\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'

-- 
Hemant Shah                           /"\  ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com       \ /  --------------------- 
                                       X     against HTML mail
TO REPLY, REMOVE NoJunkMail           / \      and postings      
FROM MY E-MAIL ADDRESS.           
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind,                Above opinions are mine only.
it's backed up on tape somewhere.      Others can have their own.


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

Date: Wed, 28 Mar 2001 22:06:40 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Question about File::Find module?
Message-Id: <Qftw6.26$Lt1.79658@news.pacbell.net>

Hemant Shah <shah@typhoon.xnet.com> wrote:

> :)> 1) File::Find::find will traverse all the filesystems, the "wanted" function
> :)>    decides what to do with the entry. This does not look like a good solution
> :)>    for me, because I have a 60GB file system (users home directory) NFS
> :)>    mounted across 20 systems, and I do not want 20 systems traversing the file
> :)>    system every night.
> :)
> :)So "prune" when you hit a NFS filesysetem.

>    That does not help. Even if I prune on NFS, find function will still
>    traverse the whole NFS file system and for every entry I will have to
>    prune.

Nonsense.  Prune stops traversing the tree and heads back up.

>    Here is a description of File::Find I found on web:
>    -----cut-------------cut-------------cut-------------cut------
> find() does a recursive subdirectory search of $dir. It calls Wanted()
> once for each file and directory in $dir, including $dir itself. You can
> actually specify a list of directories, and find() will search all of
> them.

> Typically, Wanted() begins by deciding whether it wants to operate on
> the current file. Regular expression matches on $_ do this concisely.
>    -----cut-------------cut-------------cut-------------cut------

Your quote seems old.  Why are you looking on the web?  The docs for
File::Find should be on your system?

(talking about wanted())...
    The function may set $File::Find::prune to prune the tree.

>    Example:

>    /     --> local filesystem
>    /usr  --> local filesystem
>    /apex --> nfs filesystem

>    If I execute the above find command, it will traverse /, /usr, and /apex,
>    even if I prune in my function (wanted).

What above command?

Prune works fine...

% find . -print
 .
 ./foo
 ./foo/bar
 ./bar
 ./bar/bil
 ./find.pl

Now... I don't want to see anything under foo..

perl find2perl . \( -name foo -prune \) -o -print  
% perl find.pl
 .
 ./bar
 ./bar/bil
 ./find.pl

So nothing under foo was searched.  

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
          < How are you gentlemen!! Take off every '.SIG'!! >


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

Date: Wed, 28 Mar 2001 19:22:32 GMT
From: Kim C <kimmfc@mydeja.com>
Subject: Re: Re: passing strings containing variables to subs
Message-Id: <91d4ctogjvaeh4qgj3mpeludmv4j0tt1h7@4ax.com>


Thanks for your help.  I'm afraid I posted that question in
frustration and saw the solution immediately upon looking at it again
this morning with fresh eyes.  Originally, I had been passing a string
to the log_errors sub that required no interpolation and so was quoted
with single quotes.  These remained when I inserted variables.  I
jumped to the conclusion that the problem was in passing the string.

You're right it runs just fine.

>
>>	Sun Mar 25 15:00:00 2001	Could not chdir to $some_dir: $!
>        ^^^^^^^^^^^^^^^^^^^^^^^^
>
>localtime() does not do that in list context, as you have it above.
>There is something else that you're not telling us...
>
>I cannot duplicate your problem. There is something else that
>you're not telling us...


As the code I posted assumed a problem in passing, and not the details
of the sub itself, I rewrote a "similar" chunk of code for the post.
(This also helped to disguise the fact that I haven't come to grips
with "printf" and "sprintf" yet - as you'll see in the weird print
formatting below.)  In doing so, I missed the "scalar" function that
proceeded the "localtime" function.  Here is part of the original
code, I'm certainly open to suggestions:


###################


## Example of how 'log_errors' might be called
log_errors("Could not chdir to $project_dir/infile: $!");


sub log_errors {

	open (ERRORS , ">>$error_log")|| die "Can't open error log: $!\n";
	my $old_handle = select(ERRORS);
	print "\n" , scalar localtime(time) , "\t";
	print join ("\n" , @_) , "\n";
	select ($old_handle);
	close ERRORS;

}

####################

Thanks again for your help,

Kim.


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

Date: Wed, 28 Mar 2001 16:08:46 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Re: passing strings containing variables to subs
Message-Id: <slrn9c4kmu.j7g.tadmc@tadmc26.august.net>

Kim C <kimmfc@mydeja.com> wrote:
>
>Thanks for your help.  I'm afraid I posted that question in
>frustration and saw the solution immediately upon looking at it again
>this morning with fresh eyes.  


I often troubleshoot for hours without luck, and finally decide to print
out the code. I often see the problem as I watch the pages roll out
of the printer.


>Originally, I had been passing a string
>to the log_errors sub that required no interpolation and so was quoted
>with single quotes.  These remained when I inserted variables.  I
>jumped to the conclusion that the problem was in passing the string.
>
>You're right it runs just fine.
>
>>
>>>	Sun Mar 25 15:00:00 2001	Could not chdir to $some_dir: $!
>>        ^^^^^^^^^^^^^^^^^^^^^^^^
>>
>>localtime() does not do that in list context, as you have it above.
>>There is something else that you're not telling us...
>>
>>I cannot duplicate your problem. There is something else that
>>you're not telling us...
>
>
>As the code I posted assumed a problem in passing, and not the details
>of the sub itself, I rewrote a "similar" chunk of code for the post.


That is a Very Good Idea, but you should then show only output from
your "pared down" code, not from your real code. You often uncover
the problem yourself by going through the exercise of creating
a small and complete example program.

You had us troubleshooting code that we could not see. Worse yet,
we thought we _could_ see it. A futile waste of time all around.

Please don't do that anymore.


>(This also helped to disguise the fact that I haven't come to grips
>with "printf" and "sprintf" yet - as you'll see in the weird print
>formatting below.)  


I don't see that either of those functions will help you anyway.

Looks like you want to print a list with newlines between elements.
printf() isn't going to help with that.

>In doing so, I missed the "scalar" function that
>proceeded the "localtime" function.  Here is part of the original
>code, I'm certainly open to suggestions:
                     ^^^^^^^^^^^^^^^^^^^


Good, 'cause I'm going to make some (more).

I'm not shy  :-)


>###################
>
>
>## Example of how 'log_errors' might be called
>log_errors("Could not chdir to $project_dir/infile: $!");


One minor point, I like to put delimiters around filenames so
it will be obvious if leading/trailing whitespace creep in somehow:

   log_errors("Could not chdir to '$project_dir/infile' $!");
                                  ^                   ^

>sub log_errors {
>
>	open (ERRORS , ">>$error_log")|| die "Can't open error log: $!\n";

You should include the name of the file in your diagnostic message:

   open (ERRORS , ">>$error_log")|| die "Can't open '$error_log' $!\n";


>	my $old_handle = select(ERRORS);
>	print "\n" , scalar localtime(time) , "\t";
>	print join ("\n" , @_) , "\n";
>	select ($old_handle);


I think you have displayed very poor programming practice there.

I *never* use select() just for providing a default filehandle. I
just type the name of the filehandle I want to use:

   print ERRORS "\n", scalar(localtime), "\t";   # no select() needed
   print ERRORS join ("\n" , @_) , "\n";

I like making what my code does obvious (I confuse myself with my
own Perl code often enough already), so I would replace the 
join() with:

   foreach ( @_ ) {
      print ERRORS "$_\n";
   }

or the equivalent:

   print ERRORS "$_\n" foreach @_;

or even (not recommended):

   { local $, = "\n";
     print ERRORS @_;
   }
   print ERRORS "\n";


>Thanks again for your help,

You're welcome.


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


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

Date: Thu, 29 Mar 2001 10:23:12 -0600
From: "Rich" <bigrich318@yahoo.com>
Subject: Re: Read and write a hash of arrays ?
Message-Id: <tc6o85232ru81@corp.supernews.com>


"Charles K. Clarkson" <c_clarkson@hotmail.com> wrote in message
news:7449E7C0B5F358E7.7666F9C1D739B7D2.07A7728B73B4F8B0@lp.airnews.net...
> Rich <bigrich318@yahoo.com> wrote:
> :
> : <u665313720@spawnkill.ip-mobilphone.net> wrote:
> : > Hi,
> : <snip>
> :
> : use strict;
> :
> : my %enzymes_hash;
> : my $keyword;
> :
> : while (<DATA>) {
> : if (/^(\w+)::$/) { $keyword = $1; next;};
> : my ($clone, $best_hit_id, $e_value, $percent_ident, $aln_length,
$species,
> $desc) =
> : (/^(\w+)\s+(\w+)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?\s+.*?)\s+(.*)/);
> : push(@{$enzymes_hash{$best_hit_id}}, join(" ", ($e_value, $clone,
> $best_hit_id, $percent_ident, $aln_length, $species, $desc)));
> : }
>
>     There isn't a need for all those values anymore:
>
> while (<DATA>) {
>     if (/^(\w+)::$/) { $keyword = $1; next;};
>     my @arr =
> (/^(\w+)\s+(\w+)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?\s+.*?)\s+(.*)/);
>     push @{$enzymes_hash{$arr[1]}}, join ' ', @arr[2, 0, 1, 3 .. 6];
> }
>
> HTH,
> Charles K. Clarkson

There wasn't a need for them in the first place (tmtowtdi). I tried to
provide a readable solution without changing the op's original script too
much.

Are you saying that yours is a far more efficient solution (if so, could
you give an estimate of the milliseconds it saved?) or did you simply want
to show that you could obfuscate the code a little?

What if the values were used 600 lines later in the script?

Which would be more readable if your job was to maintain the code but you
didn't write it?

if ($arr[5]) { print "The value is $arr[5]"; }

or

if ($species) { print "The value is $species"; }

If you want to obfuscate, why not write all of your code like a JAPH sig.

my($kwd,%enz);while(<DATA>){$kwd=(/^(\w+)::$/)?$1:'';(/^(\w+)\s+(\w+)\s+(.*
?)\s+(.*?)\s+(.*?)\s+(.*?\s+.*?)\s+(.*)/)?push@{$enz{$2}},join"
",($3,$1,$2,$4,$5,$6,$7):next;}

It does the same as the examples above but I'm sure that your clients
and/or co-workers would be thoroughly impressed with your programming
skills if you buried it in a couple of thousand lines of similar
obfuscation.

Thanks, but I'll take readability over obfuscation and micro-efficiency any
day.

Rich




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

Date: Wed, 28 Mar 2001 20:27:52 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Regex question
Message-Id: <x7vgoty6ye.fsf@home.sysarch.com>

>>>>> "AW" == Ave Wrigley <Ave.Wrigley@itn.co.uk> writes:

  >> BEGIN{ @words = qw( foo bar baz ) ; $" = "|" ; }
  >> 
  >> print $1 if /((?:\s*(?:\b(?:@words)\b)\s*)+)/ ;

  AW> Surely this only matches if the substring only contains @words? I.e. for:

  AW> "some text here baz foo blah foo bar more text here"

  AW> it will match:

  AW> " baz foo "

you have been much less than clear on your goal. fixing it to match any
string with has those words starting or ending it is a simple mod:

print $1 if /((?:\s*(?:\b(?:@words)\b)\s*)+.+?(?:\s*(?:\b(?:@words)\b)\s*))/ ;

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Wed, 28 Mar 2001 21:20:06 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Regex question
Message-Id: <GAxF9I.7v3@news.boeing.com>

In article <3ac1c848.677771273@news.lhr.globix.net>,
Ave Wrigley <Ave.Wrigley@itn.co.uk> wrote:
>On Mon, 26 Mar 2001 20:12:18 GMT, ced@bcstec.ca.boeing.com (Charles
>DeRykus) wrote:
>
>>Here's one using a regex... uglier though: 
>>
>>my $regex;
>>$regex .= "(?=^(.*?$_))" for @words;
>>my @sort = sort { length $a <=> length $b } $searched =~ /$regex/s; 
>>my ($trim) = $sort[0] =~/(.*?)(?:@{[join "|", @words]})/;
>>my $match = substr $sort[$#sort], length $trim;
>
>Soo ...
>
>1) $regex is a lookahead assertion for all of @words, which captures
>all the text from the begining of the string until after each of the
>words; thins for each word
>2) @sort contains these captured substrings, sorted by length
>

Yes to 1) and 2). 

>3) $trim takes the shortest of these, and does a non-greedy match up
>until the first of any of @words (could this have been achieved by not
>capturing $_ in the $regex regex?)
>

No, eventually, you'd have to re-insert $_ to generate
the complete substrings so might as well do that immediately.
Alternatively, though, you might capture $_ separately and use 
a hash to map them. I'm sure there are other alternatives too.

>4) $match is the substring of the longest of @sort from $trim to the
>end of the string
>
>So $match is a (kind of!) the substring from the first first instance
>of any of @words to the last first instance of any of @word (if you
>get what I mean!). Is thsi correct?

Yes to 4). So, this solution guarantees the first and 
shortest substring that contains all of the words. 
There may be duplicates of the earlier words though,
e.g., the match could be "baz baz foo blah foo foo bar"; 

--
Charles DeRykus


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

Date: Wed, 28 Mar 2001 14:53:57 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: regexp with multiple \n?
Message-Id: <99tfe2$tsq$1@slb3.atl.mindspring.net>

"Mark Grimshaw" <m.grimshaw@salford.ac.uk> wrote in message
news:3AC22755.97092577@salford.ac.uk...
> Hi,
>
> I'm capturing input from a FORMs-based bulletin board.  If $message is
> my input from the form, I use the following to remove all occurrences of
> \n and replace them with <BR> for return to the browser:
>
> $message =~ s/\n/<BR>/g;
>
> This works fine.
>
> However, to stop users hitting their return key multiple times and
> thereby wasting a lot of space on the webpage, I tried the following
> hoping that it would replace multiple occurrences of \n with <P> and
> then single occurrences of \n with <BR>:
>
> $message =~ s/(\n){2,}/<P>/g;
> $message =~ s/\n/<BR>/g;
>
> However, the first code produces no result.  Any solutions?

The code below should do what you want - It converts all line terminators to
whatever your system uses for "\n", trims leading and trailing whitespace
and produces well-formed XHTML to boot.

for ($message) {
    s/\015\012|\012|\015/\n/g;
    s/^\s+//;
    s/\s+$//;
    $message = join '', map {
        s/\n/<br \/>/g;
        "<p>$_</p>"
    } split /\n\n+/;
}

HTH,

Kurt Stephens







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

Date: Thu, 29 Mar 2001 10:17:08 -0600
From: Ti Leggett <leggett@americasm01.nt.com>
Subject: Re: regexp with multiple \n?
Message-Id: <3AC36004.510FEDCF@americasm01.nt.com>

Mark Grimshaw wrote:

> Hi,
>
> I'm capturing input from a FORMs-based bulletin board.  If $message is
> my input from the form, I use the following to remove all occurrences of
> \n and replace them with <BR> for return to the browser:
>
> $message =~ s/\n/<BR>/g;
>
> This works fine.
>
> However, to stop users hitting their return key multiple times and
> thereby wasting a lot of space on the webpage, I tried the following
> hoping that it would replace multiple occurrences of \n with <P> and
> then single occurrences of \n with <BR>:
>
> $message =~ s/(\n){2,}/<P>/g;
> $message =~ s/\n/<BR>/g;
>
> However, the first code produces no result.  Any solutions?

It seems to me (and I'm by no means a guru), that if you're reading line by
line this won't have any effect. However, if you're slurping in the whole
text at once (undefining $/) then this might actually do something, though
I'm not quite sure.

--
Ti Leggett
Nortel Networks
SPM Strategic Development
email: leggett@nortelnetworks.com





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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 585
**************************************


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