[8495] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2112 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 16 20:07:23 1998

Date: Mon, 16 Mar 98 17:00:33 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 16 Mar 1998     Volume: 8 Number: 2112

Today's topics:
    Re: Appending into the middle (Craig Berry)
    Re: Are there translated user messages available? <stuartc@ind.tansu.com.au>
        Buffered output <owl@fran.chisp.net>
    Re: Buffered output <sowmaster@juicepigs.com>
    Re: Delete Files via Unlink on NT?? Help! (I R A Aggie)
    Re: Exotic-Looking Microbes Turn Up In Ancient Antarcti chris+usenet@netmonger.net
        fixed length files <shawnb3@ZIPLINK.NET>
    Re: fixed length files <sowmaster@juicepigs.com>
    Re: Illegal octal digit error? <uri@sysarch.com>
    Re: Illegal octal digit error? (Jason Gloudon)
    Re: Is there a "Newsgroup" for Newbies to Perl? (I R A Aggie)
    Re: Is there a "Newsgroup" for Newbies to Perl? (John Callender)
    Re: Is there a "Newsgroup" for Newbies to Perl? <chasecreek.systemhouse@usa.net>
    Re: Listing subdirectories... <tjbtech@rtweb.net>
    Re: Multiple substitues (Bart Lateur)
    Re: NT option pack 4 (Tye McQueen)
    Re: Perl for WIN32 external system calls (Jason Gloudon)
    Re: Perl for WIN32 external system calls <ludlow@us.ibm.com>
    Re: Socket IO, non echoed? <chasecreek.systemhouse@usa.net>
    Re: Splitting a string to make keys to a hash <uri@sysarch.com>
    Re: Splitting a string to make keys to a hash (Mike Stok)
    Re: Statistics for comp.lang.perl.misc <chasecreek.systemhouse@usa.net>
    Re: Tied and blessed? (Tye McQueen)
        Why this one doesn't work ? indhiraa@hotmail.com
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 16 Mar 1998 23:08:37 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Appending into the middle
Message-Id: <6ekbdl$mmm$2@marina.cinenet.net>

Scott Nipp (snipp@spd.dsccc.com) wrote:
: 	I am creating a subroutine to insert data into the middle of an 
: existing report.  I am not a perl guru, I am running into a few problems.
: Here is a bit of the code that I am working with.

: print "Please enter end user name: "; chop($uname = <STDIN>);
: &report;

Might (as a matter of style) suggest passing in the username as a 
paramter to report ('&report($uname)') rather than via a global.  This 
makes code growth and debugging easier.

: sub report {

Insert 'my $uname = shift;' here if you take my suggestion above.

: open (REPORT,"/homes/snipp/reports/report");
: open (REPORT1,">>/homes/snipp/reports/report.tmp");

No checks for open success?

: while ($lines = <REPORT>) {

Should be 'while (defined($lines = <REPORT>) {'.  Also, the variable 
name '$lines' is a bit misleading...it will contain a single line of the 
REPORT file on each pass through the loop.

Since each branch of the if below prints out $lines first, why not put

  print REPORT1 $lines;

out here, before the if, and eliminate the else below?

:    if ($lines eq "TkTrack Activities\n") {
:       print REPORT1 $lines;
:       print REPORT1 "test $uname ";

With no newline at the end?

:    } else {
:    print REPORT1 $lines;
:      }
:    }
: }
: 
: 	Unfortunately this does not work out very well.  I am kind of at a loss
: for ideas at the moment.  This portion of the script should ideally take a 
: line of formatted data and stick it in after a heading type category in the
: report.  Here is the portion of the report where I am trying to insert this
: text.

This part isn't clear enough for me to help you, sorry to say.  Can you 
apply the cleanups above, then supply a small test case that does the 
wrong thing (as you see it)?

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 17 Mar 1998 11:15:16 +1100
From: Stuart Cooper <stuartc@ind.tansu.com.au>
Subject: Re: Are there translated user messages available?
Message-Id: <yeoyayamauj.fsf@kudu.ind.tansu.com.au>

"A. V." <avine@eng.sun.com> writes:

> I've been trying to get any sort of information on Perl library user 
> messages.  Can anyone give me a pointer?  I need to know:
 
> 1.  where they are stored (if there is a standard location),
> 2.  whether there are publicly available localizations of the user messages,
> 3.  whether it would be legal to localize any of the user message catalogs.
 
> Thanks,
> Andrea
> 
> avine@eng.sun.com
 
Nice to see some folks at eng.sun.com taking an interest in Perl; it'll
be good for you to use a fast, portable, popular language with a wide range of 
uses instead of that TCL and Java stuff. :)

By "Perl library user messages" I guess you mean warning messages that Perl
tells you when compiling or running your script. Example:

Name "main::stuart" used only once: possible typo at dumb.pl line 2.
Use of uninitialized value at dumb.pl line 2.

These messages are generated by calls to the warn() function that occur
throughout the Perl souce code (which you should have on your machine).
If you want to internationalise these; you'd either change the text of
each call; maybe devising your own warnInternational() routine to use in
place of the current one.

> 1.  where they are stored (if there is a standard location)

1) there is no standard location; the warn() calls are littered throughout
the Perl source code.

> 2.  whether there are publicly available localizations of the user messages

2) Don't know. I guess not; because the code isn't written in such a way
as to make this easily possible; the warning messages don't have numbers
or indexes associated with them or anything like that.

Look on CPAN at www.perl.com for freely available libraries of stuff.

> 3.  whether it would be legal to localize any of the user message catalogs.

3) Have a good look at the files "Copying" and "Artistic" in the source
directory of Perl. These describe the terms under which Perl is distributed
(the famous GNU GPL). Basically you can do what you like with the source code;
but anyone you give your new product to; you must give them the source code
and the freedom to modify it themselves. In my view you wouldn't be able to
call a product derived from Perl "SunScript" (TM) and distribute it in
binary only form. But it would be fine to write, say, Japanese versions
of the warning messages, and give or sell the new product, PerlJ say, to
your customers with the same rights as you have with your use of Perl.

Example:
================================================================
The XEmacs editor was developed by Sun and others from the freely available
GNU Emacs editor (in my opinion the best editor money can or can't buy) and
is now distibuted under the same terms as GNU Emacs. XEmacs enjoys considerable
popularity. Some people complain about there now being 2 very good Emacses,
and consolidation is required between the 2 sources and so on; this is
happening to some degree.
================================================================

The usual way people contibute to Perl is through adding useful modules
and submitting them to CPAN.

Hope this helps,

Stuart Cooper.
stuartc@ind.tansu.com.au


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

Date: 16 Mar 1998 23:19:08 -0700
From: "John Hankey" <owl@fran.chisp.net>
Subject: Buffered output
Message-Id: <01bd5131$e382f620$221faecf@cooper.owlscreech.com>

Is there a way in Perl to buffer output using select() and print()?

What I'm trying to do is build a dynamic webpage in a buffer and when the
process is done, flush the buffer to STDOUT.

If there is an error, I'd like to clear this buffer and print an error
instead.

Is there a preferred way to do this?

Is it possible to select a buffer instead of a file handle?

	Thank you,

		John


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

Date: Mon, 16 Mar 1998 18:52:44 -0500
From: Bob Trieger <sowmaster@juicepigs.com>
To: John Hankey <owl@fran.chisp.net>
Subject: Re: Buffered output
Message-Id: <350DBB4C.5713@juicepigs.com>

John Hankey wrote:
> 
> Is there a way in Perl to buffer output using select() and print()?
> 
> What I'm trying to do is build a dynamic webpage in a buffer and when the
> process is done, flush the buffer to STDOUT.
> 
> If there is an error, I'd like to clear this buffer and print an error
> instead.
> 
> Is there a preferred way to do this?
> 
> Is it possible to select a buffer instead of a file handle?

There are 4000+ plus ways to do this.

I think the most obvious are using CGI.pm, buffering the output to a
variable or calling separate subroutines based on the results.

HTH
Bob Trieger
sowmaster@juicepigs.com


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

Date: Mon, 16 Mar 1998 13:02:41 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Delete Files via Unlink on NT?? Help!
Message-Id: <fl_aggie-1603981302410001@aggie.coaps.fsu.edu>

In article <6ejasr$4a4$1@viper.america.net>, "Mark Polakow" <mark@imp.net>
wrote:

[posted && cc'd]

+ I have been informed about UNLINK and RMDIR but I have no idea how to =
+ use them and what it needs. COuld someone PLEASE, PLEASE, send me some =
+ code and how to use it that will delete a file/directory, I would be so =
+ appreciative! I have ignorantly tried to use this code and failed:

+ unlink("c:\inetpub\wwwroot\upload\deleteme.txt");

Check the return value:

$results=unlink _filename_;

$results will contain the number of files removed. If it is 0, then
you want to check the value of $! to see what went wrong.

rmdir works similarly, but returns a 1 if it succeeded, and a 0 if
it failed (typical true/false values). Again, $! will contain the
error message (if needed).

I bet your cgi is not permitted to remove files/directories...

Oh, and tell outlook express to not post HTML to usenet? Thanks.

James

-- 
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>


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

Date: 16 Mar 1998 23:37:57 GMT
From: chris+usenet@netmonger.net
Subject: Re: Exotic-Looking Microbes Turn Up In Ancient Antarctic Ice
Message-Id: <6ekd4l$cq7$1@schenectady.netmonger.net>

In article <kibo-1603981709460001@kibo.std.com>,
James "Kibo" Parry <kibo@world.std.com> wrote:
> What fun!  Now, kids, you too, can discover all the ASCII microbes
> in this core sample!  Remember, ASCII microbes are never more than
> one row tall.  Find and name all the microbes in this core sludge!
> 
>            ][\@#{}|{3}3{|}[3}|[}|%
>            **$U*$)(Y*($#)Y*#$Y*)#$
>            )(@^&(!@_$*%^&)(#()&$&%
>            {}$#:%}{$^}{#:%}{#%{^{:
>            >$%?.5(#?<%$4#%?<32%>6%
>            !~(#1``#*(~$($~)(%~-56$
>            >?<?:{<>>??>,./.<?,;>?,
>            ~><#?>@$}{$_+_$++%^|%+_

Now you're going to get flamed for using map in a void context.

Since tomorrow is St. Patrick's day, honoring Babylon 5's captain
Picard, I'll have to post this as-is; I have no more time to waste
obfuscating it.  The first three lines really need to be hidden, as
they give away too many secrets.  This is left as an exercise to
the reader.

#!/usr/local/bin/perl

*_=*DATA;
$,='%-=_+^~';
%h = ("000" => 10, "001" => 124, "010" => 32, "011" => 46, "100" => 47,
      "101" => 92, "110" => 95);

for(split//,<DATA>){push@@,index$/=$,,$_,};$_x=<_>;
map{$:=~s|.|$_x=~/\W*(\w)/g;$}.=$1|ges,print+chr($h{join
$@,map{($_&$")!~/\s/+$|}split//,$}})x$_;$}=$@,$:-=$=}@@;
__END__
^+-+-+--=---+----------=-------~~---_-+-_------===----~=-^=-
a HaCKer who WrOte pERL cOde quItE AtrOcIoUsLY
Was cHaLLenged To ObfuSCAtE IT ferOcIOusLY
  BuT his RYHmIng skiLlS FaILed Him
  and ThE PERl mONGErs NEarLy jaiLeD hIM
As He inExpLIcAbLy ENDeD his stuPid LImricK veRY badly


-- 
	    Christopher Masto <chris+usenet@netmonger.net>
	Director of Operations, NetMonger Communications, Inc.


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

Date: Mon, 16 Mar 1998 18:58:52 -0500
From: shawn b mcgowan <shawnb3@ZIPLINK.NET>
Subject: fixed length files
Message-Id: <350DBCBC.51AC@ZIPLINK.NET>

I am new to perl as I am sure this question will demonstrate.

I am trying to pass data to a legacy system that will only read in fixed 
length data.  I have been able to parse data from a form and write it 
out to a file but to this point I have not come up with a good way of 
padding the data.  If anyone could point me in the direction of an 
answer I would greatly appreciate it.

Thanks in advance,
Shawn McGowan

e-mail Shawnb3@ziplink.net


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

Date: Mon, 16 Mar 1998 19:37:25 -0500
From: Bob Trieger <sowmaster@juicepigs.com>
To: shawn b mcgowan <shawnb3@ZIPLINK.NET>
Subject: Re: fixed length files
Message-Id: <350DC5C4.FD1@juicepigs.com>

shawn b mcgowan wrote:
> 
> I am new to perl as I am sure this question will demonstrate.
> 
> I am trying to pass data to a legacy system that will only read in fixed
> length data.  I have been able to parse data from a form and write it
> out to a file but to this point I have not come up with a good way of
> padding the data.  If anyone could point me in the direction of an
> answer I would greatly appreciate it.


perldoc -f sprintf


HTH
Bob Trieger
sowmaster@juicepigs.com


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

Date: 16 Mar 1998 18:41:51 -0500
From: Uri Guttman <uri@sysarch.com>
To: stan@thunder.temple.edu (Stan Horwitz)
Subject: Re: Illegal octal digit error?
Message-Id: <x7ra42jj9c.fsf@sysarch.com>


here i go again into the bowels of newbiedom!


stan@thunder.temple.edu (Stan Horwitz) writes:

>       if ($in_month eq "Aug") {  $trans_month = 08;  }
>       if ($in_month eq "Sep") {  $trans_month = 09;  }

> The statements involving "Aug" and "Sep" get flagged with the following
> error messages:
> 
>   Illegal octal digit at convert.pl line 121, at end of line
>   Illegal octal digit at convert.pl line 122, at end of line

> I have no idea why Perl's complaining about just those two lines. All I
> want to do is test a field to see if its equal to the abbreviation for a
> particular month of the year and set another variable called $trans_month
> to the numerical value of that month. I am stumped! If I remove those
> statements from the program, it runs fine. If anyone can shed some light
> on this strange error, please let me know. 

because it is not a strange number but strange code! if you would read
perldata you would learn that numbers starting with 0 are assumed to be
octal. and 8 and 9 are NOT octal (both are > 7).

if you are using decimal numbers use 1,2,3 .. 8,9...
else you should be using a quoted string to assign all of those values.

if ($in_month eq "Jan") {  $trans_month = '01';  }
  ...
if ($in_month eq "Aug") {  $trans_month = '08';  }
if ($in_month eq "Sep") {  $trans_month = '09' ;  }


but the code still sux. you execute EACh if the if statement EACH
time. use elsif for all but the first:

if ($in_month eq "Jan") {  $trans_month = '01';  }
elsif ($in_month eq "Feb") {  $trans_month = '02';  }
  ...
elsif ($in_month eq "Sep") {  $trans_month = '09' ;  }
  ...


finally you should not be doing this at all! use a hash to convert a
string to a number

# intialization code
@months = qw( Jan Feb ... Nov Dec ) ;
@month_to_num{ @months } = ( '01' .. '12' ) ;

# conversion code
$month_number = $month_to_num{ $in_month } ;

this is the perlish way to do it. learn perl, write perl. don't
translate C thoughts into perl.

hope this helps,

uri

-- 
Uri Guttman                     SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----  8 years of Perl experience, Available Immediately
uri@sysarch.com              Resume and Sample code at http://www.sysarch.com
Try the Best Search Engine on the Net -------->  http://www.northernlight.com


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

Date: Mon, 16 Mar 1998 23:44:32 GMT
From: jgloudon@manitoba.bbn.com (Jason Gloudon)
Subject: Re: Illegal octal digit error?
Message-Id: <slrn6gre8f.1q.jgloudon@manitoba.bbn.com>

In article <6ek4mn$fb3$1@cronkite.ocis.temple.edu>, Stan Horwitz wrote:
>      if ($in_month eq "Jul") {  $trans_month = 07;  }
>      if ($in_month eq "Aug") {  $trans_month = 08;  }
>
>The statements involving "Aug" and "Sep" get flagged with the following
>error messages:
>
>  Illegal octal digit at convert.pl line 121, at end of line
>  Illegal octal digit at convert.pl line 122, at end of line

01,02,03,... are interpreted as octal numbers (base 8) because they start with
a leading 0 that you would not use if you meant the base ten numbers. 8 and 9 
are not valid octal digits hence the error. If you want to mean the 
_strings_ "01","02" rather than the numbers 1,2,3 say "01", "02".

Jason Gloudon


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

Date: Mon, 16 Mar 1998 12:55:35 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Is there a "Newsgroup" for Newbies to Perl?
Message-Id: <fl_aggie-1603981255360001@aggie.coaps.fsu.edu>

In article <6ejcv5$ak4$1@gaia.ns.utk.edu>, "Bob Gwynne"
<gwynne@utkux.utk.edu> wrote:

+     Mark reinforces my point.  At the very least, the FAQ should have a =
+ more useful search capability.

'grep'. Even the PoB's can 'find' in documents. See the bottom of this
post for a perl script that was posted here not too long ago. It may be
of some use to anyone wanting to search the FAQ documents.

+ Larry Wall must have decided to leave round(), =
+ ceil(), and floor() out of Perl as some sort of feature.

Yes. 'perldoc perlfaq4'

          Does perl have a round function?  What about ceil() and
          floor()? Trig functions?

          For rounding to a certain number of digits, sprintf() or
          printf() is usually the easiest route.

          The POSIX module (part of the standard perl distribution)
          implements ceil(), floor(), and a number of other
          mathematical and trigonometric functions.
[snip]
          Rounding in financial applications can have serious
          implications, and the rounding method used should be
          specified precisely.  In these cases, it probably pays not
          to trust whichever system rounding is being used by Perl,
          but to instead implement the rounding function you need
          yourself.

It would appear that rounding was intentionally left out to save people
from themselves...

+ Those functions should be added to the next version of Perl.  

They're there. 'perldoc POSIX' for more info.

+ All of the Perl books that I've seen need better indexes.

Feel free to do it, or approach the publishers and offer your services.
Oh, and please tell outlook express that you don't want to post in
HTML. Thanks.

James

#!/usr/bin/perl -w
# Q&D FAQ question lister

use strict;

for (@INC) {
  chdir $_ or next;
  chdir 'pod' or next;
  last if -f 'perlfaq.pod';
}
die "Couldn't find FAQ files in \@INC" unless -f _;

my $sep = "* " x 30;
opendir DIR, "." or die "Can't opendir: $!";
while (defined(my $item=readdir DIR)) {
  next unless $item =~ /perlfaq.?\.pod$/;
  unless (open FILE, "<$item") {
    warn "Can't open $item ($!), skipping"; next;
  }
  (my $fname = $item) =~ s/\.pod$//;
  print "$sep\n$fname\n$sep\n";   # header line
    while (<FILE>) {
      next unless s/^=head(\w+)\s+//;     # skip non-headers
        my $level = $1;
      next unless /[a-z]/;        # Skip all caps headers
        if ($level eq 1) {
          print "$fname: $_";
        } else {
          print "   $_";
        }
    }
}

__END__

-- 
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>


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

Date: 16 Mar 1998 15:47:30 -0800
From: jbc@west.net (John Callender)
Subject: Re: Is there a "Newsgroup" for Newbies to Perl?
Message-Id: <6ekdmi$a71@acme.sb.west.net>

Randal Schwartz (merlyn@stonehenge.com) wrote:
:  For years, comp.unix.wizards
: (before it became moderated) was *infested* with newbies, no matter
: how many FAQs and notices were posted.  A newbie immediately posts in
: .wizards because he/she thinks "I need to talk to a wizard about how
: to add a newline to this print!"

Makes you wonder if we could just solve all this mess without moderation, 
but merely by creating a "comp.lang.perl.wizards" group with a charter 
stating that it is explicitly intended as a newbie trap, where real 
wizards wouldn't be caught dead. And conversely, "comp.lang.perl.newbies" 
would be chartered for high-level talk by the perl-porters types.

Or why not take the stealth to an even sneakier level, and make 
"comp.lang.crey" (perl rot13'd), thus ensuring that no one except Randal, 
Tom, I R A Aggie, and Abigail would even bother.

Seriously, though, I'm not sure that the comp.unix.wizards sword cuts both 
ways. I mean, I'm not sure that newbies' prediliction for posting in 
*.wizards groups necessarily implies that they won't use *.newbies 
groups. Personally, I'd *like* to participate in a comp.lang.perl.newbies 
group, since I'd feel that my own mid-level expertise would still be 
adequate to help some folks out (while insulating me from insults based 
on my evident lack of clue).

It seems the alt.perl group might serve something of that purpose.

Or not. The whole debate strikes even *me* as being kind of silly, which 
makes it pretty darn ridiculous.
-- 
John Callender
jbc@west.net
http://www.west.net/~jbc/


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

Date: Tue, 17 Mar 1998 00:43:01 GMT
From: Sneex <chasecreek.systemhouse@usa.net>
Subject: Re: Is there a "Newsgroup" for Newbies to Perl?
Message-Id: <350DC5C1.AECC3DEF@usa.net>

You should hang out here more often :)

Birgitt Funk wrote:

> So thanks to all of you who can - and do - and like to give -
> still - some answers to some questions.
>
> Birgitt Funk





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

Date: Mon, 16 Mar 1998 18:58:29 -0500
From: Randall Stephenson <tjbtech@rtweb.net>
To: Tony.Curtis@vcpc.univie.ac.at
Subject: Re: Listing subdirectories...
Message-Id: <350DBCA3.7F32E08A@rtweb.net>

I'm afraid the function still only returns empty items in the array.
Does it matter that the code is contained in a sub routine?  It doesn't
seem like it should...

Tony.Curtis@vcpc.univie.ac.at wrote:

> This works:
>
>     opendir(D, ".");              # should check this for failure
>     my @allfiles = readdir D;
>     closedir D;
>
>     my @dirs = ();
>     for (@allfiles) {
>         next if ! -d;
>         push(@dirs, $_);
>     }
>     @dirs = sort @dirs;
>
>     print "Sub-directories are:\n";
>     print join("\n", @dirs);
>
> Alternatively the foreach could iterate over readdir in a
> scalar context to save using an intermediate array if you
> don't need to save all the other values.
>
> tony





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

Date: Mon, 16 Mar 1998 23:04:53 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Multiple substitues
Message-Id: <3510af5f.4059781@news.tornado.be>

dfrench@aig.vialink.com wrote:

>I would like to perform multiple substitues on a single line.  For instance
>using "sed" the I can do the following:
>
>sed -e "s/A/a/g;s/B/b/g;s/C/c/g" filename
>
>The content of the substitutes above were just an example, but I would like to
>do the same kind of thing in perl.  I would like to do multiple substitues in
>a single command,  somthing like:
>
>$result = s/A/a/ && s/B/b/ && s/C/c/;

Replace the "&&" by ";" and you're almost there.

But note that I am very wary of repeated substitutions, for example:

	s/#/&/; s/&/#/;

which may have been intended to replace all "#" by "&"  and vice versa,
but you'll end up replacing every  "#" and "&" by just "#". No more "&"
at all.

What I do in this case, is create a replacement hash, and replace
everything at once through the hash:

	%replace = ( 'A' => 'a', 'B' => 'b' , 'C' => 'c' );
	s/(A|B|C)/$replace{$1}/g;

This solves both your problem, and the ramification I was talking about:
	
	%replace = ( '&' => '#', '#' => '&' );
	s/(&|#)/$replace{$1}/g;

This will indeed swap all "#"'s and "&"'s.

Another example would be in replacing characters by their corresponding
HTML entities or vice versa. It does indeed scale up beautifully.

HTH,
Bart.


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

Date: 16 Mar 1998 15:53:56 -0600
From: tyde@medtrodnet.cdom (Tye McQueen)
Subject: Re: NT option pack 4
Message-Id: <6ek71k$ni6@fohnix.metronet.com>


) Bob Trieger <sowmaster@juicepigs.com> writes:
) > and when are backwhacked backwhacks
) >needed?

aml@world.std.com (Andrew M. Langmead) writes:
) When you pass a string to the command interpreter with either
) backticks, the system() function, or the open() function with the
) backtick option. Because the command interpreter has its own ideas of
) what forward slashes mean, it will mis-parse them as being options
) specifiers.

Note that the "command interpreter" is _mostly_ each individual
program.  That is, "cmd.exe" could well be called the "command
interpreter" by someone from VMS [which had a real command
interpretter] but "cmd.exe" does extremely little interpretation
of the command line and _DOES_ let you use / as a directory
separator:

    C:\Work>c:/perl/bin/perl -v

    This is perl, version 5.004_04 built for MSWin32
    [...]

But many individual commands [including, unfortunately, most,
if not all, of the commands built into "cmd.exe"] think that
"/" is for command-line options and so won't let you use it
as a directory separator.  Many [but not all] of these allow
"-" as an alternative to "/" for command-line options.

I think there used to be an environment variable that you could
set to say that you wanted to use "-" to specify command-line
options and that some commands would then let you use "/" as a
directory separator.  But I find no evidence that this idea has
survived.

I also find plenty of evidence that many programs simply "roll
their own" command parsing and pay little attention to any number
of rules like this.  This is probably because, like me, they were
not able to find any standard routines for parsing command lines. 
Even the C standard of breaking lines into distinct arguments is
pretty much trashed by the way MicroSoft has implemented it.

MicroSoft, please adopt some standard here!  [What am I saying!?]

Some GUI tools also don't allow "/" as a directory separator
despite showing absolutely no other use for the character.  It
just depends on who wrote the code that day, I guess.

Note that much Perl code won't handle "\\" as a directory
separator ["perl" itself, probably always does, but many modules
and scripts don't].  These should be fixed to use information
from "use Config", but that doesn't seem to be happening too
quickly -- "use Config" probably doesn't even contain sufficient
information for making many modules OS-independant at this point.
--
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)
       Remove d's from address to reply (sorry for the inconvenience).


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

Date: Mon, 16 Mar 1998 23:35:23 GMT
From: jgloudon@manitoba.bbn.com (Jason Gloudon)
Subject: Re: Perl for WIN32 external system calls
Message-Id: <slrn6grdnb.1q.jgloudon@manitoba.bbn.com>

In article <350D8AF4.1AF3981F@tensorex.com>, Tensor Engineering wrote:

>the PKZIP for Windows program, however what I am trying to automate
>running is "pkunzip" for DOS ie I am doing :
>  system ("c:\pkware\pkunzip $currfile");
>My question is why doesn't this work ??

Maybe because \p isn't what you think it is ? Use / or \\

Jason Gloudon


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

Date: Mon, 16 Mar 1998 17:29:49 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: Perl for WIN32 external system calls
Message-Id: <350DB5ED.A67D2A9A@us.ibm.com>

Tensor Engineering wrote:
> Hiya folks,

Hi.

> A quick question for all you Perl for WIN32 people out there.
> I am used to UNIX Perl and am trying to write several portable
> scripts for WIN32 now. What I am after is to be able to call
> an external program like :
>   system ("gunzip $currfile");
> for WIN95 platform, from what I have been experimenting and come to
> understand if I used the WIN32::Process module I can bring up
> the PKZIP for Windows program, however what I am trying to automate
> running is "pkunzip" for DOS ie I am doing :
>   system ("c:\pkware\pkunzip $currfile");
> My question is why doesn't this work ??
> I understand shell invocation on UNIX and suspect that I need to
> invoke the DOS shell to make this run but how and if there is a better
> way to write perl scripts on WIN32 and be able to call external
> programs easily.

The biggest problem is that you actually need to use a double backslash
"\\".  You also might run into a situation where it can't find
$currfile.  You may expect that it would just look in the pkware
directory, but this (probably) isn't the case.  Either change your
current working directory or just explicitly state it.  Anyway...

example:

system ("c:\\pkware\\pkunzip.exe $currfile");
--
James Ludlow (ludlow@us.ibm.com)
This isn't tech support and all opinions are my own.


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

Date: Tue, 17 Mar 1998 00:33:23 GMT
From: Sneex <chasecreek.systemhouse@usa.net>
Subject: Re: Socket IO, non echoed?
Message-Id: <350DC37F.BA9FF237@usa.net>

OK, I would agree to a point; but if I telnet to his 'server' where is
the password being displayed?  My end or his?

I mentioned what I did because (possibly wrongly) assumed that he also
wrote the 'client' to his server...   I shouldn't be thinking that hard :)

Hmmm,
Sneex :)

Uri Guttman wrote:

> Sneex <chasecreek.systemhouse@usa.net> writes:
>
> > Although I haven't done this with perl, I would assume that the same action,
> > using ANSI related modules on CPAN, probably could set the character
> > foreground color to the background color thereby hiding it.
>
> sneex,
>
> you are way off here! how can the process on this side of a socket find
> out what the colors on a remote socket?





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

Date: 16 Mar 1998 19:00:34 -0500
From: Uri Guttman <uri@sysarch.com>
To: mcravit@shell3.ba.best.com (Matthew Cravit)
Subject: Re: Splitting a string to make keys to a hash
Message-Id: <x7ogz6jie5.fsf@sysarch.com>

mcravit@shell3.ba.best.com (Matthew Cravit) writes:

> I'm trying to split a string, and use the elements of the split as keys
> to a hash. That is, if I have, for example, the string
> 
> "foo:bar:baz=99"
> 
> I'd like $SomeHash{foo}{bar}{baz} to be 99. The number of components in
> the string will vary; otherwise this would be fairly trivial. There could
> (at present) be as few as one and as many as 6 or 7 components before the
> equals sign.
> 
> Can anyone suggest an elegant way of handling this?

Dan Boorstein <dboorstein@shopcfn.com> writes:

> my ($keys, $value) = split '=', 'foo:bar:baz=99';
> $keys =~ s/:/}{/g;
> eval "\$hash{$keys} = \$value";

cute, but you don't need eval. try this:

#!/usr/local/bin/perl

$line = 'foo:bar:baz=99' ;

( $key_field, $val ) = split( '=', $line ) ;

@keys = split( ':', $key_field ) ;

$key = shift @keys ;
$last_key = pop @keys ;

$ref = $hash{ $key } = {} ;

foreach $key ( @keys ) {

	$ref = $ref->{ $key } = {} ;
}

$ref->{ $last_key } = $val ;

print "val = '$hash{foo}{bar}{baz}'\n" ;


uri

-- 
Uri Guttman                     SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----  8 years of Perl experience, Available Immediately
uri@sysarch.com              Resume and Sample code at http://www.sysarch.com
Try the Best Search Engine on the Net -------->  http://www.northernlight.com


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

Date: 17 Mar 1998 00:05:04 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Splitting a string to make keys to a hash
Message-Id: <6ekeng$kr@news-central.tiac.net>

In article <6ejvfn$v4$1@shell3.ba.best.com>,
Matthew Cravit <mcravit@shell3.ba.best.com> wrote:
>I'm trying to split a string, and use the elements of the split as keys
>to a hash. That is, if I have, for example, the string
>
>"foo:bar:baz=99"
>
>I'd like $SomeHash{foo}{bar}{baz} to be 99. The number of components in
>the string will vary; otherwise this would be fairly trivial. There could
>(at present) be as few as one and as many as 6 or 7 components before the
>equals sign.
>
>Can anyone suggest an elegant way of handling this?

One way to do it (without eval string or error checking) might be:

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

use strict;
use vars qw/%SomeHash/;

use Data::Dumper;

foreach my $line (qw /foo:bar:baz=99
                      foo:bar:boo=100
                      foo:cat:dog=123
                     /) {
  my ($keys, $val) = split /=/, $line;
  my @keys = split /:/, $keys;

  my $lastKey = pop @keys;
  my $hr = \%SomeHash;

  foreach my $key (@keys) {
    $hr = \%{$hr->{$key}};
  }
  $hr->{$lastKey} = $val;
}

print Dumper (\%SomeHash);

__END__

where Data::Dumper is just used to produce this at the end:

[mike@stok tmp]$ ./try.pl
$VAR1 = {
          'foo' => {
                     'cat' => {
                                'dog' => 123
                              },
                     'bar' => {
                                'boo' => 100,
                                'baz' => 99
                              }
                   }
        };

to see what happened.  This is not claimed to be elegant, and probably
someone has something a lot neater (I hope)

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Tue, 17 Mar 1998 00:23:16 GMT
From: Sneex <chasecreek.systemhouse@usa.net>
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <350DC11E.FC586109@usa.net>

Do I win?

:)

Greg Bacon wrote:

> Following is a summary of articles spanning a 7 day period,
> beginning at 09 Mar 1998 14:27:57 GMT and ending at
> 16 Mar 1998 09:37:11 GMT.
>
> Totals
> ======
>
> Posters:  572
> Articles: 1376 (487 with cutlined signatures)
> Threads:  461
> Volume generated: 2296.6 kb
>     - headers:    935.5 kb (18,979 lines)
>     - bodies:     1258.7 kb (38,801 lines)
>     - original:   856.2 kb (28,341 lines)
>     - signatures: 101.1 kb (1,942 lines)
>
> Original Content Rating: 0.680
>
> Averages
> ========
>
> Posts per poster: 2.4
>     median: 1.0 post
>     mode:   1 post - 373 posters
>     s:      4.4 posts
> Posts per thread: 3.0
>     median: 2 posts
>     mode:   1 post - 155 threads
>     s:      4.0 posts
> Message size: 1709.1 bytes
>     - header:     696.2 bytes (13.8 lines)
>     - body:       936.7 bytes (28.2 lines)
>     - original:   637.1 bytes (20.6 lines)
>     - signature:  75.2 bytes (1.4 lines)
>
> Top 10 Posters by Number of Posts
> =================================
>
>          (kb)   (kb)  (kb)  (kb)
> Posts  Volume (  hdr/ body/ orig)  Address
> -----  --------------------------  -------
>
>    58   105.7 ( 46.9/ 58.8/ 30.7)  sneaker@earthling.net
>
> These posters accounted for 19.8% of all articles.
>
> Top 10 Posters by Volume
> ========================
>
>   (kb)   (kb)  (kb)  (kb)
> Volume (  hdr/ body/ orig)  Posts  Address
> --------------------------  -----  -------
>
>  105.7 ( 46.9/ 58.8/ 30.7)     58  sneaker@earthling.net
>
> These posters accounted for 20.8% of the total volume.
>
>
> Top 10 Crossposters
> ===================
>
> Articles  Address
> --------  -------
>
>        9  sneaker@earthling.net





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

Date: 16 Mar 1998 15:13:00 -0600
From: tyde@medtrodnet.cdom (Tye McQueen)
Subject: Re: Tied and blessed?
Message-Id: <6ek4ks$co7@fohnix.metronet.com>

Jean-Louis Leroy <jll@skynet.be> writes:
) 
) I may soon have the need to tie a hash and have it behave like
) an object as well. 
) Is that allowed? I tried the following, which almost worked:
[...]
) As you see, DESTROY is called twice; I speculate that one
) accounts for untying and the other for the object going out of scope.

If you want some sample code for this, you can get my Tie::Registry
from CPAN.  I'm not sure why you want both tied and object [to
me it seemed a natural thing to do, but your needs could be very
different from mine], but the way you've done it you can't
distinguish object "member data" from entries in the tied hash [as
far as I can tell].  I think you'll run into some nasty circular
dependancies when you try to implement a non-trivial object that
way.

So I added one level of indirection which, among other things,
allows me to handle the 3 calls that I get to DESTROY:

    sub DESTROY
    {
      my $self= shift(@_);
	if(  tied(%$self)  ) {
	    return;	# untie-ing -- nothing special needs to be done.
	}   # or destroying the phony "proxy object" -- nothing to do.
	# else Destroying the underlying object:
	[...]
    }

The basic trick is to have an object implemented as a blessed
reference to a hash table.  To make this easier to understand,
we'll give this hash table a name, %members, since it will
hold the member data:

    $object= \%members;
    bless $object, Your::Package;

Then you can tie a different hash table to the object you
just created and have your users use a reference to it:

    my %tied;
    tie %tied, ref($object), $object;
    $proxy_obj= \%tied;

Where the above "tie" function calls your "sub TIEHASH" and uses
the first argument to be the object the hash is to be tied to:

    sub TIEHASH
    {
      my( $this )= shift(@_);
      my( $object )= @_;
	if(  1 == @_  &&  ref($object)  &&  $object =~ /=/  ) {
	    # They fed us the object to be tied to:
	    return $object;
	}
	# else, some other type of contructor required here...
	[...]
    }

Then bless this reference so that is too can be used to make
method calls:

    $proxy_obj= \%tied;
    bless $proxy_obj, Your::Package;

Finally you return $proxy_obj to your users for them to
use as either a reference to a tied hash or an object, or
both.  Perl will translate `$proxy_obj->{HASHKEY}' into
`$object->FETCH("HASHKEY")' for you and your code can translate
`$proxy_obj->SomeMethod()' into `$object->SomeMethod()' by
having each method start like:

    sub SomeMethod
    {
      my $self= shift(@_);
	$self= tied(%$self)   if tied(%$self);
	[...]
    }

How you actually implement this will be quite different.  For one
thing, %members will be an anonymous hash whose reference you got
via:

    $self= {};

But the above makes the diagram easier to draw:

    Your::Package                    Your::Package
         ^                                ^
         |                                |
       bless                            bless
         |                                |
    $proxy_obj --ref--> %tied --tie--> $object --ref--> %members

_Don't_ use the code I've shown above to try to implement this!
I think it makes the underlying workings easier to explain, but
it does the "wrong thing" in too many places.

Perhaps this should be an addition to perlbot.pod?  Depends on
whether this is seen as a neat programming tool or a kludge that
abuses Perl's machinery.  ;>  Or this may already be documented
and I haven't run into it yet [or didn't recognize it].

Comments welcome.  I've meant to post this description just to
see what people thought of it, but I hadn't found the time before.
--
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)
       Remove d's from address to reply (sorry for the inconvenience).


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

Date: Mon, 16 Mar 1998 17:39:28 -0600
From: indhiraa@hotmail.com
Subject: Why this one doesn't work ?
Message-Id: <6ekd3v$7u2$1@nnrp1.dejanews.com>

I have a PERL program whose first 3 lines are like this:

#!/bin/sh
# this line will be comment for PERL \
exec perl "$0" $@"

print "hello..\n";

My intention is to avoid hard-coding the path to the Perl interpreter.
but this script continuously execs and never goes beyond that.

Am I missing anything here.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 2112
**************************************

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