[16859] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4271 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 9 06:10:26 2000

Date: Sat, 9 Sep 2000 03:10:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <968494211-v9-i4271@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 9 Sep 2000     Volume: 9 Number: 4271

Today's topics:
    Re: name of downloaded file ... <britsaysoops@homestead.com>
        Need DB_Btree help (Billy Goat Gruff III)
    Re: Packet problem (Joe Smith)
    Re: Packet problem <jon@king-fu.freeserve.co.uk>
    Re: Perl & NT (Homer Simpson)
        Perl game Query (Christopher Tauss)
    Re: Regular Expressions <rick.delaney@home.com>
    Re: Regular Expressions <jeffp@crusoe.net>
    Re: Regular Expressions <anmcguire@ce.mediaone.net>
    Re: use strict: why? <uri@sysarch.com>
    Re: use strict: why? (Tim Hammerquist)
    Re: Variable not accepting value <uri@sysarch.com>
        What does "magic" mean? <webmaster@wholefamily.com>
    Re: what is the best way to get the lastest line from a <uri@sysarch.com>
    Re: what is the best way to get the lastest line from a (Abigail)
    Re: xml parsing (Eric Bohlman)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 9 Sep 2000 00:07:07 -0500
From: "Britney Says Oops" <britsaysoops@homestead.com>
Subject: Re: name of downloaded file ...
Message-Id: <39b9c4cc$0$370$45beb828@newscene.com>

Somewhere I found the header "Content-disposition: attachment;
filename=NAME.EXT\n" which seems to work. Just print it out with your
"content-type" header, replacing NAME.EXT with the filename you want to use.


"Tina Mueller" <tina@streetmail.com> wrote in message
news:8p1i64$c5rk4$2@ID-24002.news.cis.dfn.de...
hi,
In comp.lang.perl.misc peter pilsl <pilsl@goldfisch.atat.at> wrote:

> I´ve a script that put out some File for viewing/downloading via
> webbrowsers. (in example it puts out an file of type image/gif)
> This script is called via a <href>-link and when someone tries to download
> this file with his browser the default-name for the downloaded file is
> scriptname.ext where ext corresponds to the content-type.

really? that's cool. so the filename is set to
scriptname.jpeg if you set jpeg as content type?
if i try it the filename is always set to  the
full scriptname scriptname.cgi (or .pl).

> But I want to give this file a different name than the scriptname is. I am
> looking for a way how to set this default-filename for downloading.

one possibility is to use $cgi->path_info.
call the script with
scriptname/param1/param2/filename.whatever

and the filename will be filename.whatever

HTH,
tina

--
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \__,_\___/\___/_| /__/ perception
please don't email unless offtopic or followup is set. thanx




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

Date: Sat, 09 Sep 2000 05:11:32 GMT
From: TrollKiller@for-romance.com (Billy Goat Gruff III)
Subject: Need DB_Btree help
Message-Id: <39b9c6af.41631290@news.earthlink.net>

I am creating commerce script that will require more then one store's
information to be stored under one users ID. I want to use dup keys
with DB_Btree. I know how to enter and read the dup keys

My problem is how do I delete or change just one of the dup keys and
keep the others? 

Any help will be appreciated. If you know of any
resource to learn DB_Btree on the net please send the site.

Thanks Mike

================================
Leah's Body Sugaring Recipe
Make it yourself and save
http://www.for-romance.com/sugar
==================================


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

Date: 9 Sep 2000 05:44:19 GMT
From: inwap@best.com (Joe Smith)
Subject: Re: Packet problem
Message-Id: <8pcinj$2q38$1@nntp1.ba.best.com>

In article <8pc0p4$7if$1@news6.svr.pol.co.uk>,
King Fu <jon@king-fu.freeserve.co.uk> wrote:
>
>"Jeff Pinyan" <jeffp@crusoe.net> wrote in message
>news:Pine.GSO.4.21.0009081233040.23350-100000@crusoe.crusoe.net...
>> On Sep 8, King Fu said:
>>
>> >But the problem is i dont seem to be able to print 4B properly to the
>socket
>> >as it gets converted into ascii.
>>
>> If your problem is you don't know how to print an ASCII character by hex
>> value (like printing the character 'a', whose hex value is 61), then do:
>>
>>   print chr(0x61);  # prints 'a'
>>
><snip>
>
>No the problem is i dont know how to print 4B without it being converted
>into ascii..if that makes any sense? lol

It is NOT being converted to ASCII - it is already in ASCII.  It appears
that you are asking how to convert from ASCII to a string of hex characters.
Use sprintf("%02X",$char) for each character in the string.

>heres an example of some data from a packet of what i want todo which might
>help:
>
>0030:  21 80 6D 87 00 00 48 54 54 50 2F 31 2E 30 20 33    !.m...HTTP/1.0 3
>
>                               ^^^^^
>how would i print the two 00 00 hex values? or any for that matter?

    # Build a string with mixed binary and printable characters.
    # (This is to simulate a string that came from reading a socket.)
    $string = "!\x80m\x87\x00\x00HTTP/1.0 3";		# Build string

    # Now convert each byte to two hex digits and a blank.
    $hexstring = join " ",
		map {sprintf "%02X",ord $_}
		split "",$string;			# Build hex string
    ($printable = $string) =~ tr /\x20-\x7e/./c;	# "." for unprintable
    print STDOUT $hexstring," = ",$printable,"\n";	# Readable format


    	-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Sat, 9 Sep 2000 10:46:42 +0100
From: "King Fu" <jon@king-fu.freeserve.co.uk>
Subject: Re: Packet problem
Message-Id: <8pd1da$8g1$1@news8.svr.pol.co.uk>

<SNIP>
> >
> >No the problem is i dont know how to print 4B without it being converted
> >into ascii..if that makes any sense? lol
>
> It is NOT being converted to ASCII - it is already in ASCII.  It appears
> that you are asking how to convert from ASCII to a string of hex
characters.
> Use sprintf("%02X",$char) for each character in the string.
>
> >heres an example of some data from a packet of what i want todo which
might
> >help:
> >
> >0030:  21 80 6D 87 00 00 48 54 54 50 2F 31 2E 30 20 33    !.m...HTTP/1.0
3
> >
> >                               ^^^^^
> >how would i print the two 00 00 hex values? or any for that matter?
>
>     # Build a string with mixed binary and printable characters.
>     # (This is to simulate a string that came from reading a socket.)
>     $string = "!\x80m\x87\x00\x00HTTP/1.0 3"; # Build string
>

Thanx! doing the above did the trick, obviously what i was doing was missing
out the "\x" to specify a hex digit. I can't thank you enough. However by
just sending $string to the socket works fine...why are all those statements
below required?


>     # Now convert each byte to two hex digits and a blank.
>     $hexstring = join " ",
> map {sprintf "%02X",ord $_}
> split "",$string; # Build hex string
>     ($printable = $string) =~ tr /\x20-\x7e/./c; # "." for unprintable
>     print STDOUT $hexstring," = ",$printable,"\n"; # Readable format
>
>
>     -Joe
> --
> See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.




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

Date: 9 Sep 2000 06:45:02 GMT
From: homer.simpson@springfield.nul (Homer Simpson)
Subject: Re: Perl & NT
Message-Id: <8pcm9e$ape$0@216.39.131.146>

In article <39B88BD5.79F21814@pacific.net.hk>, Brian Leung <brianlk@pacific.net.hk> wrote:
>Hello all,
>Is it possible that someone can add user account by perl script in NT 4
>or win 2000?
>Thanks

Active Perl html documentation shows:
Win32::NetAdmin
UserCreate(server, userName, password, passwordAge, privilege, homeDir,        
 comment, flags, scriptPath)


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

Date: 09 Sep 2000 06:32:28 GMT
From: ct60@aol.com (Christopher Tauss)
Subject: Perl game Query
Message-Id: <20000909023228.06672.00000410@ng-df1.aol.com>

Hello again Perl Community -

Does anyone know if there is available Perl modules for playing backgammon?
Creating such a program is an enormous challenge and I would really like to see
how others may have attempted it.

Thanks.


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

Date: Sat, 09 Sep 2000 04:27:05 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Regular Expressions
Message-Id: <39B9BE97.7AC4A059@home.com>


Jeff Pinyan wrote:
> 
> >    /(["'<])(.*?)[\1>]/ and print $2;
> 
> I believe this is because character classes must be know at regex-compile
> time.  \1 is not known until DURING the regex.  What DOES [\1]
> become?  I'm quite curious.  -mre=debug tells me nothing useful.

Run it through again as

    /(["'<])(.*?)[\ca>]/

or as

    /(["'<])(.*?)[\x1>]/

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Sat, 9 Sep 2000 00:43:32 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Regular Expressions
Message-Id: <Pine.GSO.4.21.0009090042510.23350-100000@crusoe.crusoe.net>

On Sep 9, Rick Delaney said:

>Jeff Pinyan wrote:
>> 
>> I believe this is because character classes must be know at regex-compile
>> time.  \1 is not known until DURING the regex.  What DOES [\1]
>> become?  I'm quite curious.  -mre=debug tells me nothing useful.
>
>Run it through again as
>
>    /(["'<])(.*?)[\ca>]/

Ah, it thinks it's an octal escape.  I was thinking it was
SCALAR(0x....), as in

  $x = \1;
  /[$x]/;

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



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

Date: Sat, 9 Sep 2000 02:38:17 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: Regular Expressions
Message-Id: <Pine.LNX.4.21.0009090233020.7039-100000@hawk.ce.mediaone.net>

On Sat, 9 Sep 2000, Dietmar Staab quoth:

~~ Date: Sat, 09 Sep 2000 02:16:29 +0100
~~ From: Dietmar Staab <dietmar.staab@t-online.de>
~~ Newsgroups: comp.lang.perl.misc
~~ Subject: Re: Regular Expressions
~~ 
~~ In article <8pbv2v$4c7$17$1@news.t-online.com>, "Dietmar Staab"
~~ <dietmar.staab@t-online.de> wrote:
~~ > In article <MPG.142307bef60e9aa298ad4b@nntp.hpl.hp.com>, Larry Rosler
~~ > <lr@hpl.hp.com> wrote:
~~ > 
~~ >>     /([<"'])(.*?)\1/ and print $2;
~~ > 
~~ > Doesn't work, because left and right delimiter are not equal for <>
~~ > 
~~ > /(["'<])(.*?)[\1>]/ and print $2;
~~ > 
~~ > should fix it.
~~ 
~~ Not yet. If the string contains a "<"; better match the delimiter twice
~~ without using \1

If the data is consistent, this will do the trick:

#!/usr/bin/perl
use strict;
use warnings;

while (<DATA> =~ /^\S+\s+\S+\s+.(.*).$/)
{
        print "$1\n";
}

__DATA__
Testing stuff <BDI.delimited.catalog.ETOWN@redknife.net>
Testing stuff "BDI.delimited.catalog.ETOWN@redknife.net"
Testing stuff 'BDI.delimited.catalog.ETOWN@redknife.net'


anm
-- 
BEGIN { $\ = $/; $$_ = $_ for qw~ just another perl hacker ~ }
my $J = sub { return \$just }; my $A = sub { return \$another };
my $P = sub { return \$perl }; my $H = sub { return \$hacker  };
print map ucfirst() . " " => ${&$J()}, ${&$A()}, ${&$P()}, ${&$H()};



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

Date: Sat, 09 Sep 2000 04:15:43 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: use strict: why?
Message-Id: <x7og1yi4k1.fsf@home.sysarch.com>

>>>>> "GJ" == Gwyn Judd <tjla@guvfybir.qlaqaf.bet> writes:

  >> my       @word = qw/do you see what I see/;
  >> local    @word[2,-1] = ("know") x 2;

  GJ> interesting...if we make it:

  GJ>          local   @word = ("blah");

  GJ> we get:

  GJ>          Can't localize lexical variable @word at - line 4.

  GJ> but it works with the array slice...hmmm...does that mean the my
  GJ> variable is lexical in scope but the array elements get listed in the
  GJ> symbol table?

local affects the VALUE of any variable. you can localize an element of
a hash or an array and since you can localize multiple values, you can
localize slices. 

this is part of the lunacy moronzilla is babbling about. local does not
create any variables. it just pushes a new value onto the existing one
and at the end of the block, the old value is restored. if you pass a
named variable to local, it must be visible in the symbol table which is
why you can't localize my'ed vars.

in general, it is best to forget all these wacky uses of local and just
use it for perl variables, typeglobs and the few other things mentioned
by mjd in his article about 7 uses for local.

and misquoting that article is another moronzilla stupidity. showing 7
reasons local should be used does not extrapolate to saying it is best
used all the time.

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: Sat, 09 Sep 2000 07:43:45 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: use strict: why?
Message-Id: <slrn8rjr8v.jv.tim@degree.ath.cx>

Ben Kennedy <bkennedy99@home.com> wrote:
> There is nothing wrong with encouraging new users to use all
> the diagnostic tools available to them.  I don't think it should be an
> absolute rule for all programming, but it should be an absolute rule if you
> are seeking help from people on this group.

This is a beautiful summary of my feelings as well.  Thank you. =)

-- 
-Tim Hammerquist <timmy@cpan.org>

Not all who wander are lost.
	-- J.R.R. Tolkien


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

Date: Sat, 09 Sep 2000 04:25:06 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Variable not accepting value
Message-Id: <x7its6i44d.fsf@home.sysarch.com>

>>>>> "JJ" == Joe Johnston <jjohn@cs.umb.edu> writes:

  >> my @path = split(/^A/, $in{QUESTION_PATH});
  >> for (my $i = 0; $i < $#path; $i++) {


  JJ> for (my $i = 0; $i < @path - 1; $i++ ){ ... }

  JJ> It is such a common mistake to forget that $#path is the last index 
  JJ> of the array @path. You might want to emphasis that you are not going

and both of you are skipping the last entry in @path. let's assume there
are 10 elements in @path, indexed from 0-9. both of your loops are
comparing $i to 9 and therefore fail when $i == 9. 

the proper loop idiom to access all elements of an array is:

	for (my $i = 0; $i < @path ; $i++ )

but in general c style for loops are rarely needed in perl so look for
way to use foreach loops instead.

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: Sat, 9 Sep 2000 09:05:49 +0200
From: "Shimon Bollinger" <webmaster@wholefamily.com>
Subject: What does "magic" mean?
Message-Id: <39b9d397@news.barak.net.il>

Several Perl features are described as "magical".  Is there a well defined
technical meaning to "magical" or is it just a shortcut for "intuitive,
though nonetheless surprising"?  I checked out PERGUTS but am unilluminated.

--
/****************************************
 *  Shimon Bollinger
 *  Rehov Zait Shemen 17/8
 *  Efrat
 *  ISRAEL
 *  02/930-9411
 *  from USA: 011-972-2-930-9411
 *  bollinge@netvision.net.il
 *****************************************/




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

Date: Sat, 09 Sep 2000 04:20:28 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: what is the best way to get the lastest line from a file?
Message-Id: <x7lmx2i4c4.fsf@home.sysarch.com>

>>>>> "JJ" == Joe Johnston <jjohn@cs.umb.edu> writes:

  JJ> You have no doubt read the other responses about 
  JJ> File::Backward and using the external Unix command 

File::ReadBackwards.pm

  JJ> tail(1). I would choose tail(1) if it was most 
  JJ> convenient. I submit the code below for your

huh? it is much slower and not portable. how is that more convenient?

  JJ> amusement. It is all Perl and will return the 
  JJ> last line of non-newline text in a file. It
  JJ> was tested on Linux. Your mileage may vary, 
  JJ> so please experiment. 

  JJ> It is very weird Perl because it looks 
  JJ> at the file character by character. I 
  JJ> haven't had to do this since my bad old 
  JJ> C/Pascal days. 

  JJ>     while( seek FH, -$i++, 2 ){
  JJ> 	my $buf;
  JJ> 	read FH, $buf, 1;
  JJ> 	if( $buf eq "\n" ){
  JJ> 	    next unless $seen_non_newline;
  JJ> 	    last;
  JJ> 	}else{
  JJ> 	    $seen_non_newline++;
  JJ> 	    $last = $buf . $last;
  JJ> 	}
  JJ>     }

i am not amused by bad code like this. calling seek, read for each byte
is horrendously slow. read the code for File::ReadBackwards.pm
for a better and much faster way to actually do this. and it doesn't
read the file char by char.

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: 09 Sep 2000 04:58:53 GMT
From: abigail@foad.org (Abigail)
Subject: Re: what is the best way to get the lastest line from a file?
Message-Id: <slrn8rjgqh.b1k.abigail@alexandra.foad.org>

Uri Guttman (uri@sysarch.com) wrote on MMDLXVI September MCMXCIII in
<URL:news:x7lmx2i4c4.fsf@home.sysarch.com>:
:: >>>>> "JJ" == Joe Johnston <jjohn@cs.umb.edu> writes:
:: 
::   JJ> You have no doubt read the other responses about 
::   JJ> File::Backward and using the external Unix command 
:: 
:: File::ReadBackwards.pm
:: 
::   JJ> tail(1). I would choose tail(1) if it was most 
::   JJ> convenient. I submit the code below for your
:: 
:: huh? it is much slower and not portable. how is that more convenient?

Much slower? It's faster.

    $ cat ./rb.pl
    #!/opt/perl/bin/perl -w

    use strict;
    use File::ReadBackwards;

    tie *BW, 'File::ReadBackwards', '/etc/passwd' or die $!;

    print reverse map {scalar <BW>} 1 .. 10;

    __END__
    $ cat ./tail.pl
    #!/opt/perl/bin/perl -w

    use strict;

    open my $fh => "tail -10 /etc/passwd |" or die $!;
    while (<$fh>) {print}
    close $fh or die $!;

    __END__
    $ time ./rb.pl > /dev/null

    real    0m0.115s
    user    0m0.080s
    sys     0m0.010s
    $ time ./tail.pl > /dev/null

    real    0m0.037s
    user    0m0.000s
    sys     0m0.020s
    $


And by using tail, you can stick to normal Perl idiom of using
filehandles, open/<>/close, instead using ties (or some horrible OO
interface).



Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
#    A bee flying. A
#    thief stealing under a hazel.
#    A darting carp.


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

Date: 9 Sep 2000 06:14:27 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: xml parsing
Message-Id: <8pckg3$nqg$1@slb6.atl.mindspring.net>

Abigail (abigail@foad.org) wrote:
: That's of course an extrememly bad way of parsing xml. It doesn't deal
: correctly with:
: 
:     <foo bar = ">">text</foo>

Not well-formed; '>' has to be entified in attribute values.

:     <!-- <> -->
:     <foo/>
:     <[ CDATA [ <foo> ]]>

Not well-formed; CDATA sections must be introduced by '<[CDATA[' with no 
embedded spaces.

:     <? flurp ?>

Not well-formed: no space is allowed between '<?' and a pitarget.

:     <foo>text<foo>text</foo>text</foo>

But your general point is well-taken.  An even more serious problem with 
hack-parsing XML is that you almost always lose the ability to deal with 
character references and entity references; IOW you wind up making lots 
of assumptions about purely lexical details that are supposed to be 
transparent.



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

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 V9 Issue 4271
**************************************


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