[9713] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3310 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 1 21:04:53 1998

Date: Sat, 1 Aug 98 18:01:31 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 1 Aug 1998     Volume: 8 Number: 3310

Today's topics:
    Re: number (6 -> 06) conversion question (Lack Mr G M)
    Re: number (6 -> 06) conversion question (David Cantrell)
        Passing Large Numbers of Parameters to Subroutines <george.kuetemeyer@mail.tju.edu>
    Re: Passing Large Numbers of Parameters to Subroutines (Kelly Hirano)
    Re: Programmer's Editor (Larry Rosler)
    Re: Q:How to "mkdir -p"? <merlyn@stonehenge.com>
    Re: Q:How to "mkdir -p"? (Mark-Jason Dominus)
        Re[4]: QUERY_STRING sometimes missing from GET using CG christopher@tokpela.com
        REPORT: HELP MULTIPLE SELECT perl/javascript/html nestor@cadence.com
        REPORT: HELP MULTIPLE SELECT perl/javascript/html nestor@cadence.com
        restore STDIN <lucasda@prl.research.philips.com>
    Re: serialization and perl <dgris@rand.dimensional.com>
    Re: What's the future of Perl? (Jon Hamilton)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Thu, 30 Jul 1998 16:15:22 BST
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: number (6 -> 06) conversion question
Message-Id: <1998Jul30.161522@ukwit01>

In article <6pptn3$q0b$1@news.nyu.edu>, amd0978@acf2.nyu.edu (Adam Donahue) writes:
|> 
|> Let's say I want to convert the output of localtime so that anything less
|> than 10 gets a leading zero.  Is there a quick and easy way of doing
|> this?  I came up with 
|> 
|> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
|>    map { if ($_ < 10) {"0" . $_} else {$_} } localtime(time);
|> 
|> but this doesn't seem as elegant as it could be. ;-)  Any other
|> suggestions?

   Thinking?

   The output from localtime is an array of numbers.  The concept of a
leading zero doesn't really have much concept at that point.  If you
don't believe me see what happens if you add one to such a number.

   What you want is for the leading 0 to be there when you *display* it.

   Use printf and a format of %2zd for the number.


----------- Gordon Lack ----------------- gml4410@ggr.co.uk  ------------
The contents of this message *may* reflect my personal opinion.  They are
*not* intended to reflect those of my employer, or anyone else.



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

Date: Thu, 30 Jul 1998 16:08:04 GMT
From: NukeEmUp@ThePentagon.com (David Cantrell)
Subject: Re: number (6 -> 06) conversion question
Message-Id: <35c196ab.1590537@thunder>

On 30 Jul 1998 13:50:27 GMT,
  amd0978@acf2.nyu.edu (Adam Donahue) enlightened us thusly:

>
>Let's say I want to convert the output of localtime so that anything less
>than 10 gets a leading zero.  Is there a quick and easy way of doing
>this?  I came up with 
>
>($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
>   map { if ($_ < 10) {"0" . $_} else {$_} } localtime(time);
>
>but this doesn't seem as elegant as it could be. ;-)  Any other
>suggestions?

Extending this question a bit, is there an elegant way of zero-padding
a number to an arbitrary length.  For instance, padding to make all
numbers 4 figures ... 6 -> 0006, 37 -> 0037, and so on ...

I thought that sprintf was the way to go, but having gone through the
docs and K&R I can't figure out what the format should be.

Current yucky solution: 

print padprint("0",6, $n); # Pad $n with zeroes to make 6 chars.

sub padprint()
  { local($padChar, $totalChars, $data, $result)=(@_, '');
    for($i=0;$i<$totalChars-length($data);$i++)
      { $result.=$padChar; }
    return $result.$data; }

--
David Cantrell, part-time NT/java/SQL techie
                full-time chef/musician/homebrewer
                http://www.ThePentagon.com/NukeEmUp


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

Date: Thu, 30 Jul 1998 18:52:57 -0400
From: George Kuetemeyer <george.kuetemeyer@mail.tju.edu>
Subject: Passing Large Numbers of Parameters to Subroutines
Message-Id: <35C0F949.A7BCD0D2@mail.tju.edu>

I'm trying to develop a reasonable approach to passing parameters in
Perl subroutines. Some of my routines require many (often the same)
parameters, so explicitly passing large numbers of individual parameters
to subroutines seems ungainly. Usage of global variables is generally
considered a bad thing, even in Perl (we all know the Perl motto), so
I've started using a %v hash, which I define in an initialization
routine and then pass around to various routines as a reference. See
below for a simple example. This method is working OK for me, but I
sometimes wonder if I'm not fooling myself. Is passing around that hash
reference really much different from using global variables?. If I
misspell a key value, for example, that's the same as misspelling a
variable name. I'm wondering if anyone can suggest ways to safeguard
this approach (check for undefined values, etc.) or another approach
altogether?

-------------------------------------------------Sample
Code---------------------------------------------------------------------

main: {
    my $v = init_program();
    my %v = %$v;
    $v{newString} = combine_strings($v);
    print_new_string($v);
}

sub init_program {
    my %v;
    $v{var1} = "The quick brown fox ";
    $v{var2} = "jumped over the lazy dog."";
    # and so on and so forth, maybe params coming in from CGI, etc.,
references to arrays/other hashes, etc.
    # return reference to hash
    return \%v;
}

sub combine_strings {
    my $v = shift; my %v = %$v;
    return "$v{var1} $v{var2}";
}

sub print_new_string {
    my $v = shift; my %v = %$v;
    print "$v{newString}\n";
}

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



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

Date: 30 Jul 1998 16:22:14 -0700
From: hirano@Xenon.Stanford.EDU (Kelly Hirano)
Subject: Re: Passing Large Numbers of Parameters to Subroutines
Message-Id: <6pqv76$b4e@Xenon.Stanford.EDU>

In article <35C0F949.A7BCD0D2@mail.tju.edu>,
George Kuetemeyer  <george.kuetemeyer@mail.tju.edu> wrote:
>variable name. I'm wondering if anyone can suggest ways to safeguard
>this approach (check for undefined values, etc.) or another approach
>altogether?

be sure to use the -w flag when you run perl (e.g., #!/usr/local/bin/perl -w)
and use strict (and to help understand error messages/warnings, use
diagnostics).
-- 
Kelly William Hirano	                    Stanford Athletics:
hirano@cs.stanford.edu	                 http://www.gostanford.com/
hirano@alumni.stanford.org      (WE) BEAT CAL (AGAIN)! 100th BIG GAME: 21-20


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

Date: Fri, 31 Jul 1998 07:04:56 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Programmer's Editor
Message-Id: <MPG.102b6edf9de7b79e9897a9@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <Ewyo56.6IB@world.std.com> on Fri, 31 Jul 1998 13:29:30 GMT, 
Andrew M. Langmead <aml@world.std.com> says...
> Alan Silver <alan@find-it.furryferret.uk.com> writes:
> 
> >Despite my love for UNIX (especially compared with the pathetically
> >inferior Microsoft alternative), it is *not* the case that perl=UNIX.
> 
> No perl isn't Unix, but in the book Programming Perl, Larry Wall
> described it with phrases like "Perl is the portable distillation of
> Unix culture."
> 
> Not only are so many of the language constructs designed to mimic the
> common unix tools (shell quoting constructs, C like operators, so many
> functions being C library functions, unix-like regular expressions,
> etc.) but the whole concept of a "glue language" language makes little
> sense unless you have unix-like small tools to glue.

"...common unix tools (... C like operators, so many functions being C 
library functions, ..."

I was busy agreeing until you slipped from the Perl == UNIX fallacy into 
the C == UNIX fallacy!

> Yes, perl has been ported to other environments, I use the Windows and
> Macintosh ports all the time, but it looses something when it doesn't
> have the rest of the unix environment to interact with.

As has been discussed here, with the notable exception of robust IPCs, 
Perl on Windows/DOS *does* have the rest of the Unix environment to 
interact with (file model, shell and commands).  'inferior Microsoft 
alternative' -- definitely.  But, thanks to these tools and no thanks to 
Microsoft, 'pathetically inferior' not.

No hablo Mac.

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 01 Aug 1998 23:33:31 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Q:How to "mkdir -p"?
Message-Id: <8cu33wnupp.fsf@gadget.cscaper.com>

>>>>> "Derek" == Derek  <dereks@fc.hp.com> writes:

Derek> I want to do the equivalent of mkdir -p (i.e. greate all directories in
Derek> the path at once) in Perl.  Obviously, I could just use backticks, but I
Derek> prefer to use stuff that's native to perl if possible.  Also I could
Derek> write some iterative thing, but I'm sure there's already a tidy solution
Derek> somewhere.

Well, the tidy solution is not further away than your standard library.

    use File::Path;
    mkpath(['/some/where/out/there']);

Just like the docs say. :-)

Get to know "perldoc perlmodlib".  Saves lots of time and troubles.

print "Just another Perl hacker,"

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 1 Aug 1998 19:58:27 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Q:How to "mkdir -p"?
Message-Id: <6q0a33$eea$1@monet.op.net>

In article <35C38061.2BB3EBEB@fc.hp.com>, Derek  <dereks@fc.hp.com> wrote:
>I could write some iterative thing, but I'm sure there's already
>a tidy solution somewhere.

Hey, if you need to iterate, you have no choice but to iterate.

Although I can imagine a solution where the iteration is buried in a
`map'.

>Any ideas?

This appears in a program I use a lot, but I haven't ever tested it
carefully, so beware.

sub mkdir_p {
  my ($dir, $mode) = @_;
  my $pdir = '';
  
  my @components = split(m./., $dir);
  foreach $c (@components) {
    $pdir .= $c . '/';
    next if -d $pdir;
    if (-e $pdir) {
      warn "File `$dir' already exists, but is not a directory! Skipping.\n";
      return 0;
    } else {
      my $pdirp = $pdir;
      chop $pdirp;
      my $rc = mkdir $pdirp, $mode;
      unless ($rc) {
        next if $! =~ /exists/;
	warn "Couldn't make directory `$pdirp': $!.  Skipping.\n";
	return undef;
      }
    }
  }
  return 1;
}

Caution: This is not portable to systems without directories.










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

Date: Sat, 01 Aug 1998 22:55:48 GMT
From: christopher@tokpela.com
Subject: Re[4]: QUERY_STRING sometimes missing from GET using CGI.pm
Message-Id: <6q06dl$arr$1@nnrp1.dejanews.com>

Thanks Thomas!

This may very well be the problem but I need to check with my ISP to see
which version they have installed (since I do not have access to the library
files on this account).  But now at least I know that I am not going crazy.

Thanks again,

Christopher Taranto

In article <35C255D5.D87D47ED@daimi.aau.dk>,
  thomas@daimi.aau.dk wrote:
> christopher@tokpela.com wrote:
> >
> > Thanks for your response - but I am already using CGI.pm
> >
> > Is there a case where the QUERY_STRING variable is not set or somehow
missed?
>
> what version are you using?
>
> if you look at the description for v2.17 it says:
>
> "Fixed bad bug in query_string() method that caused some parameters to
> be silently dropped."
>
> maybe that is the problem, if you are using an earlier version
>

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Sat, 01 Aug 1998 22:53:39 GMT
From: nestor@cadence.com
Subject: REPORT: HELP MULTIPLE SELECT perl/javascript/html
Message-Id: <6q069k$ai7$1@nnrp1.dejanews.com>

I have a perl/cgi program that creates a html page for user to enter data
and a file gets written when the submit button is clicked.  In a SELECT
stament any time I use the MULTIPLE argument the file does not get written
completely, but when I remove the MULTIPLE argument the entire file gets
written.  Whenever the submit button is clicked then a javascript is set to
gather all selected choices from the SELECT statment.
This works fine for a SINGLE SELECT statement, but not for a MULTIPLE SELECT.
When using the MULTIPLE statment, the file gets written but it stops writing
when it tries to write the  field for the select statement after the first
selection. Maybe, I am not gathering the information from the SELECT field
correctly.  How do you gather the information on a MULTIPLE SELECT?

Anyone know of better way of listing a directory ina MULTIPLE SELECT and
grabing all the files chosen? or Can anyone help me on my code?

Thanks in advance,

Nestor Alberto Florez

-------
JAVASCRIPT code:
  function gettechfiles()
  {
    var files="";
    for (var i=0; i < document.f.tech_file.options.length ; i++)
    {
      if(document.f.tech_file.options[i].selected)
      {
        files = files + document.f.tech_file.options[i].value + " ";
      }
    }
    document.f.tech_file.value = files;
  }


------------------ PERL code: sub TechBrowser {  $ESH_tech_dir =
"/net/hostname/usr5/techfiles";  if( opendir TECH_DIR,"$ESH_tech_dir")	{ 
print"<PRE>\n";  print "<B>  Select Technology File</B>  <SELECT
NAME=\"tech_file\" SIZE= 3 MULTIPLE >\n";  @allfiles = sort
grep(!/^\.\.?$/,readdir(TECH_DIR));

     if($#allfiles > 0)
     {
       $ESH_tech_file = "";
       print "<OPTION SELECTED>$ESH_tech_file\n";
       foreach $file (@allfiles)
       {
          print "<OPTION> $file \n";
       }
     }
     else
     {
       $ESH_tech_file = "Empty Directory";
       print "<OPTION SELECTED>$ESH_tech_file\n";
     }

     print "</SELECT>\n";
     closedir(TECH_DIR);
   }
}

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Sat, 01 Aug 1998 22:53:33 GMT
From: nestor@cadence.com
Subject: REPORT: HELP MULTIPLE SELECT perl/javascript/html
Message-Id: <6q069d$ahd$1@nnrp1.dejanews.com>

I have a perl/cgi program that creates a html page for user to enter data
and a file gets written when the submit button is clicked.  In a SELECT
stament any time I use the MULTIPLE argument the file does not get written
completely, but when I remove the MULTIPLE argument the entire file gets
written.  Whenever the submit button is clicked then a javascript is set to
gather all selected choices from the SELECT statment.
This works fine for a SINGLE SELECT statement, but not for a MULTIPLE SELECT.
When using the MULTIPLE statment, the file gets written but it stops writing
when it tries to write the  field for the select statement after the first
selection. Maybe, I am not gathering the information from the SELECT field
correctly.  How do you gather the information on a MULTIPLE SELECT?

Anyone know of better way of listing a directory ina MULTIPLE SELECT and
grabing all the files chosen? or Can anyone help me on my code?

Thanks in advance,

Nestor Alberto Florez

-------
JAVASCRIPT code:
  function gettechfiles()
  {
    var files="";
    for (var i=0; i < document.f.tech_file.options.length ; i++)
    {
      if(document.f.tech_file.options[i].selected)
      {
        files = files + document.f.tech_file.options[i].value + " ";
      }
    }
    document.f.tech_file.value = files;
  }


------------------ PERL code: sub TechBrowser {  $ESH_tech_dir =
"/net/hostname/usr5/techfiles";  if( opendir TECH_DIR,"$ESH_tech_dir")	{ 
print"<PRE>\n";  print "<B>  Select Technology File</B>  <SELECT
NAME=\"tech_file\" SIZE= 3 MULTIPLE >\n";  @allfiles = sort
grep(!/^\.\.?$/,readdir(TECH_DIR));

     if($#allfiles > 0)
     {
       $ESH_tech_file = "";
       print "<OPTION SELECTED>$ESH_tech_file\n";
       foreach $file (@allfiles)
       {
          print "<OPTION> $file \n";
       }
     }
     else
     {
       $ESH_tech_file = "Empty Directory";
       print "<OPTION SELECTED>$ESH_tech_file\n";
     }

     print "</SELECT>\n";
     closedir(TECH_DIR);
   }
}

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 30 Jul 1998 15:47:24 GMT
From: Adrian Lucas <lucasda@prl.research.philips.com>
Subject: restore STDIN
Message-Id: <35C0958C.4F64612C@prl.research.philips.com>

Is it possible in Perl (under HPUX version of Unix) to read from the
keyboard but exit with anything initially on STDIN still there for
subsequent scripts/programs?

The reason is that I want a pause program called in .login that waits a
certain time or until a key is pressed.  Got this working fine but when
I start a telnet session specifying a command to be executed (which is
queued on STDIN) the command gets swallowed by the pause.

Any help appreciated.
  
-- 

Adrian Lucas   Office Systems Manager, Philips Research Laboratories 
               Redhill, Surrey RH1 5HA, England
E-mail:        lucasda@prl.research.philips.com
Phone:         +44 (0)1293 815131  Fax: +44 (0)1293 815500


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

Date: Fri, 31 Jul 1998 00:04:27 GMT
From: Daniel Grisinger <dgris@rand.dimensional.com>
Subject: Re: serialization and perl
Message-Id: <6pr0ug$lu5$1@rand.dimensional.com>

[posted to comp.lang.perl.misc and mailed to the cited author]

In article <6po29f$ov5$1@cnn.Princeton.EDU>
imkirnos@CS.Princeton.EDU (Ilya M. Kirnos) wrote:
>Does perl have any facilities for writing out/reading in perl data
>structures, e.g. hashes?  I'm looking for something akin to serialization
>in java.  Thanks.

use Data::Dumper; # :-)

dgris



-- 
Daniel Grisinger           dgris@perrin.dimensional.com
"No kings, no presidents, just a rough consensus and
running code."
                           Dave Clark


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

Date: 31 Jul 1998 02:10:31 GMT
From: hamilton@pobox.com (Jon Hamilton)
Subject: Re: What's the future of Perl?
Message-Id: <6pr92n$bdu@newsops.execpc.com>

On 30 Jul 1998 16:12:21 GMT, Tom Christiansen <tchrist@mox.perl.com> wrote:
} 
} In comp.lang.perl.misc, 
}     qcoldiro@deal.unl.edu writes:
  
[...]

} :I have wondered is will Perl every get a Case or Switch statement?
} 
} As for a switch statement, we spell that "for", 
} 
}     for ($variable) {
} 	if (/foo/) { ...... }
} 	if (/bar/) { ...... }
} 	# etc
}     } 

We may spell it "for", but we had better work in the letters in
"anchor" in there as well:

  $variable = 'booger';

  for ($variable){
    if(/boo/) { print "Oops, caught picking nose!\n"; }
  }

Changing the if to /^boo$/ of course does what was probably intended.  

-- 

   Jon Hamilton 
   hamilton@pobox.com


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 3310
**************************************

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