[6271] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 893 Volume: 7

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 4 17:57:31 1997

Date: Tue, 4 Feb 97 12:00:21 -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           Tue, 4 Feb 1997     Volume: 7 Number: 893

Today's topics:
     Re: [Q] Sorting Keys numerically <smcculla@sms.ivey.uwo.ca>
     Re: Anyone got a base64 encoder? <jander@jander.com>
     Re: Associative array efficiency <rootbeer@teleport.com>
     Re: DNS lookups in perl (Joey Gibson)
     Re: DNS lookups in perl <jander@jander.com>
     Re: dropping trailing zeroes when "write (FA).... <mcampbel@tvmaster.turner.com>
     Re: flock() question <rootbeer@teleport.com>
     Re: How can I create associative arrays from variables? (Kevin Buhr)
     Re: http authentication <ama@cimad.be>
     Looking for a Win32 pm module for paging <nbonfigl@3do.com>
     Re: Looking for a Win32 pm module for paging (Nathan V. Patwardhan)
     Re: Looking for a Win32 pm module for paging (Nathan V. Patwardhan)
     mail and perl - help <josephn@mail.mcoe.k12.ca.us>
     Re: mail and perl - help (Nathan V. Patwardhan)
     Re: Newbie questions (Mark Hazen)
     Re: Patch to add threads to Perl5.003 (Mark Daku)
     Re: perl and linux?? (Kevin Buhr)
     Q:How to change current working directory? <jonesaa@worldnet.att.net>
     Re: Q:How to change current working directory? (Mike Stok)
     Resizing jpegs <jasonw@zeta.org.au>
     Resizing jpegs <jasonw@zeta.org.au>
     Resizing jpegs <jasonw@zeta.org.au>
     Re: Shell "case" command in perl (Kevin Buhr)
     Re: Shell "case" command in perl (Neil S. Briscoe)
     Re: Trimming Dollar Value (Chris Nandor)
     Re: Trimming Dollar Value (Tad McClellan)
     Re: UNIX-based perl: backgrounding and file descriptors (Kevin Buhr)
     Win32 simple telnet. Not getting login prompt. pcarty@eurokom.ie
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: Tue, 4 Feb 1997 10:07:07 -0500
From: "Stephen B. McCullagh" <smcculla@sms.ivey.uwo.ca>
To: Chris Nandor <pudge@pobox.com>
Subject: Re: [Q] Sorting Keys numerically
Message-Id: <Pine.LNX.3.93.970204100316.15344B-100000@sms.ivey.uwo.ca>

Thanks to Chris, Jim, Bennett, and E. for quick
responses to my query.  All of the info was helpful.

Regards,
Steve
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  Stephen B. McCullagh             E-mail: smcculla@sms.ivey.uwo.ca 
  Richard Ivey School of Business  Office: Room 2312 IBS                      
  University of Western Ontario    Phone : (519) 661-2111 x 5134            
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::




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

Date: 04 Feb 1997 14:45:54 -0500
From: Jim Anderson <jander@jander.com>
Subject: Re: Anyone got a base64 encoder?
Message-Id: <bua04aod.fsf@jander.com>

allen@gateway.grumman.com (John L. Allen) writes:

> 
> In article <01bc1248$910c77f0$1f7fe484@mlbweb>,
> Rick Osborne <osborri@mail.northgrum.com> wrote:
> >I need the algorithm for base64 encoding in perl.  Anyone got?  I'd also
> >like to find some perl for BinHex4, if anyone's got it, but I've got the
> >C++ for that and can always convert if no one does...
> 
> Check CPAN.  But for a cryptic and minimalist implementation try
> 
> Encoding:
> 
> #!/bin/perl
> $_=pack(u,$_),y|!-`|B-Za-z0-9+/A|,
> $e=2-ord()%3,s/.{$e}$/'='x$e/e,
> s/.//,print while read STDIN,$_,45
> 
> Decoding:
> 
> #!/bin/perl -p
> s/=*\n//,$_=y|B-Za-z0-9+/A|!-`|<y///c
> ?"":unpack u,chr(32+.75*y///c).$_

Two other options:

1. MIME::Base64 from the libwww-perl package.

2. I'm working on a much faster, more efficient base64 perl5
   implementation which should be available in 2-3 weeks. This will be
   useful if you need to encode/decode very large files.

-- 
Jim Anderson			jander@jander.com
PGP Public Key Fingerprint:	0A 1C BB 0A 65 E4 0F CD
				4C 40 B1 0A 9A 32 68 44


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

Date: Tue, 4 Feb 1997 10:07:34 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: JAMES STRANGIO <james.strangio@eq.gs.com>
Subject: Re: Associative array efficiency
Message-Id: <Pine.GSO.3.95.970204094952.14176D-100000@linda.teleport.com>

On Fri, 31 Jan 1997, JAMES STRANGIO wrote:

> Does anyone know how much less efficient (if at all) it is to use
> associative arrays than regular scalar variables?  

I hesitate to give anything precise, but as a rule-of-thumb, I'd _guess_
that retrieving a hash element is about half as fast as retrieving a
simple scalar, and a quick test with Benchmark seems to agree with that.

> I have a bunch of cgi-script that use about 100 pseudo-global variables. 
> It's easy for debugging to say 'foreach (sort keys %ARR)' and then print
> out these variables. 
> 
> But I noticed when I switched from perl4 to perl5, my program became
> *much* slower. 

Just about everything sped up in the switch from perl4 to perl5. But if
you're using any deprecated features, that might account for the slowdown. 
But I don't know of any way in which hashes have slowed down. 

If you've got 100 elements in that hash, you can alias them to scalars for
convenience with the method in this code. Since they're aliased, as you
see, you can modify one to affect the other; they're really the same
variable. I don't know what this will do to the speed, though, and this
won't convert the hash keys into syntactically valid variables. Hope this
helps! 

    #!/usr/bin/perl -w

    use strict;

    # Turn a hash into scalars.
    {
	no strict 'refs';
	my $name;
	for $name (keys %ENV) {
	    *$name = \$ENV{$name};
	}
    }

    use vars qw#$PATH#;
    print "My \$PATH is now $PATH.\n";
    $PATH = '/bin:/usr/bin';
    print "My \$PATH is now $PATH.\n";
    print "My \$ENV{PATH} is now $ENV{PATH}.\n";
    __END__

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Mon, 03 Feb 1997 14:00:55 -0500
From: joeyGibson@mindspring.com (Joey Gibson)
Subject: Re: DNS lookups in perl
Message-Id: <32fa348b.6578499@news.mindspring.com>

On Tue, 4 Feb 1997 16:13:32 +0100, Jonas Oberg <kmm96jog@mds.mdh.se>
wrote:
||| Is it possible to do a DNS lookup from inside a perl script?
||| I've got a program which is piped a message and picks out the bare bone
||| sender address (Such as jonas@coyote.eu.org) in $sender. I now want to
||| lookup the primary mail exchanger for coyote.eu.org.  I'd like something
||| like
||| $mx = lookupprimarymx($sender);
||| 
||| Is this possible, and if so, how?  I was thinking about opening a pipe to
||| nslookup but I'm not sure how you do both reads and writes.

Here is a Perl script I wrote last year to simulate NSLookup. It is
actually quite easy. There isn't really any error checking, but you can
adapt it however you want. I wrote this under WindowsNT, but it should
work with any Perl 5.

Here it is:

#!/usr/local/bin/perl
#
# NSLookUp -- Similary to the nslookup program.
#
# HISTORY:
# 05/01/96   Joey Gibson   Original code.
#

# Obligatory banner message...
print "NSLookUp v1.0 | Portico Software | 05/01/96 07:51\n";

die "\nUsage: nslookup hostName\n" if ! @ARGV;

# Fetch the info from the DNS server.
($name, $aliases, $addrType, $length, @addresses) = gethostbyname
$ARGV[0];

# If a NULL list is returned, the host info could not be found.
die "\nUnknown host [$ARGV[0]]!\n" if ! $name;

# We must decode the address.
($a, $b, $c, $d) = unpack 'C4', $addresses[0];

# Now display the requested information.
print sprintf "\n%s: %d.%d.%d.%d\n", $name, $a, $b, $c, $d;


--
/| Joey Gibson - VB/PB/C++ Developer, JAPH , Right-Wing Extremist!
||   joeyGibson@mindspring.com /\ www.mindspring.com/~joeygibson/
|| [I]t isn't so much that liberals are ignorant. It's just that
||       they know so much that isn't so. - Ronald Reagan
\|     Get my PGP key from a key-server. Key-ID: 0x16817A11



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

Date: 04 Feb 1997 14:51:52 -0500
From: Jim Anderson <jander@jander.com>
Subject: Re: DNS lookups in perl
Message-Id: <afpk4aef.fsf@jander.com>

Jonas Oberg <kmm96jog@mds.mdh.se> writes:

> 
> Hi!
> 
> Is it possible to do a DNS lookup from inside a perl script?
> I've got a program which is piped a message and picks out the bare bone
> sender address (Such as jonas@coyote.eu.org) in $sender. I now want to
> lookup the primary mail exchanger for coyote.eu.org.  I'd like something
> like
> $mx = lookupprimarymx($sender);
> 
> Is this possible, and if so, how?  I was thinking about opening a pipe to
> nslookup but I'm not sure how you do both reads and writes.
> 
> ------[ Jonas - Just another intelligent shade of blue ]------
> http://www.mds.mdh.se/~kmm96jog - PGP key available via finger
> --------------------------------------------------------------
> 
===========================================================================
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: DNS resolver module available for testing
Date: 27 Jan 1997 00:28:00 -0700

The DNS resolver module I've been working on is available for
testing.  You can get it from:

    http://www.dimensional.com/~mfuhr/perldns/

This initial version is for testing and shouldn't be considered ready
for production use.  There are a few known bugs but in general it works,
at least on my system.  Any comments regarding bugs and portability
would be appreciated.  Contributed scripts using the module are also
welcome and may be included in future versions.

Enjoy :-)
-- 
Michael Fuhr
http://www.dimensional.com/~mfuhr/
===========================================================================

-- 
Jim Anderson			jander@jander.com
PGP Public Key Fingerprint:	0A 1C BB 0A 65 E4 0F CD
				4C 40 B1 0A 9A 32 68 44


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

Date: 04 Feb 1997 13:16:35 -0500
From: Mike Campbell <mcampbel@tvmaster.turner.com>
Subject: Re: dropping trailing zeroes when "write (FA)....
Message-Id: <r5enewjv24.fsf@tvmaster.turner.com>

Tom Phoenix <rootbeer@teleport.com> writes:

> > If a variable is "2.0" coming from &crossoverTable, the write (FA)
> > command drops the zero and the decimal and writes "2" into the
> > output file.  How can I make it keep the trailing zero and thus
> > keep the correct number of significant figures?
> 
> There's nothing internally different between the numbers 2.0 and
> 2.00000000, but you can choose which one to print out by using printf or
> sprintf. Hope this helps!

You also might want to try @###.# instead of @<<<<< in the format, if
you know ahead of time the number if places after the decimal you
need.


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

Date: Tue, 4 Feb 1997 09:41:11 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Fabian Thylmann <nathan@club.innet.be>
Subject: Re: flock() question
Message-Id: <Pine.GSO.3.95.970204093614.14176B-100000@linda.teleport.com>

On Tue, 4 Feb 1997, Fabian Thylmann wrote:

> I use flock in a lot of my scripts and am getting a little confused. The
> way I understood it, when you use flock(FILE,2); it will lock the file
> and when you use flock(FILE,8); it will unlock it. Now I also thought
> that when someone comes along and used flock(FILE,2); AGAIN on the same
> file and the first script didn't unlock it yet, the second script will
> automatically sleep until it can gain a lock on the file. Is this
> correct, or not?

Yes, although you should know that locks are automatically released when a
file is closed (or when the process exits, which closes all files). Also,
locking may not work for files shared over NFS and similar methods,
unfortunately. 

I think you could might like to read Randal's fourth Web Techniques
column, which explains how to use flock() to avoid problems when multiple
processes need to modify one file. Hope this helps!

   http://www.stonehenge.com/merlyn/WebTechniques/

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: 04 Feb 1997 12:46:29 -0600
From: buhr@stat.wisc.edu (Kevin Buhr)
Subject: Re: How can I create associative arrays from variables?
Message-Id: <vba20awmmt6.fsf@mozart.stat.wisc.edu>

Noemi Preissner <noemi@coli.uni-sb.de> writes:
> 
> I am interested in something like ${$2}{$1} = "yes";
> (which obviously is not the right way to do it ... )

Oh ho!  But it *is*!

#!/usr/bin/perl
$x = "array";
$y = "key";
${$x}{$y} = "value";
print "The first value is '$array{key}'.\n";
"foo,bar" =~ /(.*),(.*)/o;
${$1}{$2} = "bonk";
print "The second value is '$foo{bar}'.\n";

In fact, "$$x{$y}" works fine, too, though "$$1{$2}" doesn't.

Kevin <buhr@stat.wisc.edu>


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

Date: Tue, 04 Feb 1997 18:26:14 +0100
From: Andre Marien <ama@cimad.be>
To: cbusch@member.com
Subject: Re: http authentication
Message-Id: <32F77136.3760@cimad.be>

Chris Busch wrote:

> Some of our www directories are password protected using http
> authentication.  This requires a person to log in with a username and
> password.  My question is: how can we force netscape to reprompt the
> user for a login if they want to change usernames?  Right now, you have
> to quit all of the netscape apps, and restart so netscape will forget
> that you have access to that www directory.

> Any suggestions?

Invalidate the 'cache':
Hav a server return a 401 code for a document in the top of the
protected tree,
despite the authentication. Direct the user to that page by any means.
It may be difficult if your server has no hooks to do it, of course.
(or you must allow [nph] scripts in the doc directory)

You could use client pull to invalidate a password after a certain
inactivity  time this way.

Hope this helps,

-- Andre'


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

Date: 4 Feb 1997 17:28:48 GMT
From: "Nick Bonfiglio" <nbonfigl@3do.com>
Subject: Looking for a Win32 pm module for paging
Message-Id: <01bc12c0$e13ec7a0$2f1ed3c6@tyson>

I'm looking for a perl5 Win32 pm module that will send alpha pages.  Please
send responses to nbonfigl@3do.com.

nb


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

Date: 4 Feb 1997 17:29:44 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Looking for a Win32 pm module for paging
Message-Id: <5d7rm8$gps@fridge-nf0.shore.net>

Nick Bonfiglio (nbonfigl@3do.com) wrote:
: I'm looking for a perl5 Win32 pm module that will send alpha pages.  

Sorry for the question, but what's an alpha page? (I'm not kidding - I just
don't know).

--
N Patwardhan
nvp@shore.net
send me mail
	--Jamie Zawinski


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

Date: 4 Feb 1997 18:34:35 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Looking for a Win32 pm module for paging
Message-Id: <5d7vfr$l8q@fridge-nf0.shore.net>

Nathan V. Patwardhan (nvp@shore.net) wrote:
: Nick Bonfiglio (nbonfigl@3do.com) wrote:
: : I'm looking for a perl5 Win32 pm module that will send alpha pages.  

Okay.  Some pointed out that this is for a *pager*, not a page in the
sense of paper, or web (two common, recent threads).  Is this for a pager?

--
N Patwardhan
nvp@shore.net
send me mail
	--Jamie Zawinski


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

Date: 4 Feb 1997 17:26:20 GMT
From: "joseph norris" <josephn@mail.mcoe.k12.ca.us>
Subject: mail and perl - help
Message-Id: <01bc12c9$704926e0$274d04c7@josephn.mcoe.k12.ca.us>

I have finished producing some reports via perl that run on a monthly
basis.
 I would like to email these to those who should get them but I am unsure
has to how to do this. I've seen examples of how to open mail via a pipe
but I don't know how to attach a file to this email. 
Can you give me any suggestions? Thanks joseph.

-- 
 
    Joseph Norris     			   
                                          
    email : josephn@mail.mcoe.k12.ca.us   
                                          
    Mendocino County Office Of Education   
 



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

Date: 4 Feb 1997 18:11:15 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: mail and perl - help
Message-Id: <5d7u43$j77@fridge-nf0.shore.net>

joseph norris (josephn@mail.mcoe.k12.ca.us) wrote:
:  I would like to email these to those who should get them but I am unsure
: has to how to do this. I've seen examples of how to open mail via a pipe
: but I don't know how to attach a file to this email. 
: Can you give me any suggestions? Thanks joseph.

$file = '/foo/bar/file.txt';
$mailprog = '/usr/lib/sendmail';
$subject = 'Monthly Report';
$users = 'foo@bar.com, her@his.com, him@hers.com';

open(MAILER, "|$mailprog -s \"$subject\" $users")
    || die(Cannot open mailer!: $!\n");
open(FILE, "$file")
    || die("yoohoo: $!\n");
while(<FILE>) {
    print MAILER $_;
}
close(FILE)
close(MAILER);


--
N Patwardhan
nvp@shore.net
send me mail
	--Jamie Zawinski


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

Date: 4 Feb 1997 17:17:13 GMT
From: mhazen@spock.fcs.uga.edu (Mark Hazen)
Subject: Re: Newbie questions
Message-Id: <5d7qup$c5s@hobbes.cc.uga.edu>

Chris Raettig ['Scooby'] etched this into electrons:

: Please bear with me :)

Not a problem. :-)

: 1) How can I make the output of my Perl program appear at the bottom of a HTML
: file. I have written a counter program which outputs text. I don't think this is
: classed actually as a CGI script, or is it?

To include CGI output in an existing HTML page, rename the page to
"whatever.shtml", and add this line at the bottom:

<!--#exec cgi="path_from_doc_root_to_your_program.cgi" -->

Assuming Server side includes and CGI are supported by your server, this
will make your shtml (html parsed for server side includes) file include the
output of your CGI program. Make certain the script has the proper rights to
be executed by the server, too! (usually 705 is the correct rights setting
for NCSA standard servers).

And, yes, it *is* a CGI script. ANYTHING executed on a server which outputs
through a web server is using the CGI gateway... ergo, they're all CGI. So
is this:
          #!/usr/bin/perl
           print "Content-type: text/html\n\nHIYA!\n";     

 ...even if it's kinda short. ;)


: 2) Is there a function that would return the number of lines in a text file?

Sure... in Perl? If the file is short, just open the file, do a
"@lines=<FILEHANDLE>"; and then say something like "$num_lines=@lines;".
This will put the number of items (lines) in the file into $num_lines.

For longer files:

my $counter=0;
open(HANDLE,"<filename");
while($current_line=<HANDLE>) {$counter++;}
close(HANDLE);

 ...should do the trick. Someone with more Perl knowledge may have a more
gracedul solution.

: 3) What is the best way of seeding the random number generator? Doing it via
: time seems to lead to similar results if the numbers are taken in a very short
: time period.

I use time; time is drawn from the seconds count, so the numbers would have
to very close indeed. Try generating 1000 random numbers between 0 and 1000
and check your distribution. Of course, YMMV.... I'm using Perl 5.003 on a
Linux system (Redhat 4.0).

-Mh.

-- 
: Mark Hazen                                    mhazen@fcs.uga.edu   
: Family & Consumer Sciences at UGA             Bitnet: mhazen@uga
: http://www.fcs.uga.edu/~mhazen
:
: Good communication is as stimulating as 
: black coffee, and just as hard to  sleep after. -Anne Morrow Lindbergh  
 


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

Date: 04 Feb 1997 12:04:08 -0500
From: daku@nortel.ca (Mark Daku)
Subject: Re: Patch to add threads to Perl5.003
Message-Id: <esqenewbj07.fsf@nortel.ca>

eanders@u98.CS.Berkeley.EDU (Eric Arnold Anderson) writes:

Wow!!  

This has huge potential.  The number of thing that I would like to bea
able to do with threads is huge.

I would really like to see what Larry, Tom, Chip ...... would have to say
about it.  I would really like this to be the perl 5.005 update.  Thus
making it the prominant new feature for 5.005.  

The only issues I have are with speed, hits.  It would be very nice to
have a really clean way of turning threads off or on.  Maybe by the
command "use threads".  But I imagine all have this concern.  Oh and of
course affected robustness of perl.

Great Work Eric.

This will be a great addition to an already powerful language.

Mark Daku
daku@nortel.ca


> I've created a patch that adds threads to Perl5.003; since this
> requires that the interpreter and any extensions are recompiled, and
> since it hasn't been extensively tested, I haven't submitted it yet to
> CPAN, and am just making it available from a web page.  The web page
> is: <http://www.cs.berkeley.edu/~eanders/thrperl/>; since we've been
> having some trouble with file servers, you may also try the reference
> <http://now.cs.berkeley.edu/~eanders/thrperl/>.  The release notes
> from the patch are included below.
> 	-Eric
> 


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

Date: 04 Feb 1997 12:32:26 -0600
From: buhr@stat.wisc.edu (Kevin Buhr)
Subject: Re: perl and linux??
Message-Id: <vbad8ugmngl.fsf@mozart.stat.wisc.edu>

plan9@inetworld.net writes:
>
> is it possible to run perl thru linux?

Yes.  All common Linux distributions, including Debian, Slackware, Red
Hat, and Caldera come with complete, new versions of Perl.  If you
prefer to do it yourself, the Perl source tree includes a "linux"
configuration profile and should compile without difficulty.

Kevin <buhr@stat.wisc.edu>


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

Date: Tue, 04 Feb 1997 12:51:15 -0600
From: Anthony Jones <jonesaa@worldnet.att.net>
Subject: Q:How to change current working directory?
Message-Id: <32F78523.2612@worldnet.att.net>

I know there is a simple explaination for this, but I don't have it.

How can you change the current working directory inside a perl script?

The reason I am asking is, I have to untar a file in the directory where
the file resides, NOT in the directoy I run the script from, or the home
directory of the user.  The tar file is created to untar to the current
(.) directory.

Thanks for the help

Anthony Jones


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

Date: 4 Feb 1997 19:18:03 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Q:How to change current working directory?
Message-Id: <5d821b$7ab@news-central.tiac.net>

In article <32F78523.2612@worldnet.att.net>,
Anthony Jones  <jonesaa@worldnet.att.net> wrote:
>I know there is a simple explaination for this, but I don't have it.
>
>How can you change the current working directory inside a perl script?
>
>The reason I am asking is, I have to untar a file in the directory where
>the file resides, NOT in the directoy I run the script from, or the home
>directory of the user.  The tar file is created to untar to the current
>(.) directory.

You can use chdir which should be a builtin function e.g.

  $dir = '/etc';
  chdir $dir or die "chdir $dir failed ($!)\n";
  system 'head passwd';

should display the first few lines of /etc/passwd on a unix-like system.

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@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: Wed, 5 Feb 1997 06:11:42 +1100
From: "jason Wraxall" <jasonw@zeta.org.au>
Subject: Resizing jpegs
Message-Id: <01bc12cf.41914160$8de402cb@Godzilla>

Dear all,

Does anyone know of a library which will alow me to resize jpeg images?

I need to be able to run it on an alpha with the IIS.

Thanks in advance,

Jason


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

Date: Wed, 5 Feb 1997 06:11:42 +1100
From: "jason Wraxall" <jasonw@zeta.org.au>
Subject: Resizing jpegs
Message-Id: <01bc12cf.5c823a60$8de402cb@Godzilla>

Dear all,

Does anyone know of a library which will alow me to resize jpeg images?

I need to be able to run it on an alpha with the IIS.

Thanks in advance,

Jason


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

Date: Wed, 5 Feb 1997 06:11:42 +1100
From: "jason Wraxall" <jasonw@zeta.org.au>
Subject: Resizing jpegs
Message-Id: <01bc12cf.7de7ba40$8de402cb@Godzilla>

Dear all,

Does anyone know of a library which will alow me to resize jpeg images?

I need to be able to run it on an alpha with the IIS.

Thanks in advance,

Jason


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

Date: 04 Feb 1997 12:36:08 -0600
From: buhr@stat.wisc.edu (Kevin Buhr)
Subject: Re: Shell "case" command in perl
Message-Id: <vba7mkomnaf.fsf@mozart.stat.wisc.edu>

perisse@urbi.com.br (Jan-Patrick Perisse Sys. Admin) writes:
>
> How would a bash "case" look like in perl?
>  I've been reading the book and found nothing about it.

Check out the perlsyn(1) manpage.  There's a section headed "Basic
BLOCKs and Switch Statements" that gives eight (gack!) different
constructs for implementing a "switch" (or "case") statement in Perl.

Kevin <buhr@stat.wisc.edu>


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

Date: 4 Feb 1997 19:11:54 GMT
From: neilb@zetnet.co.uk (Neil S. Briscoe)
Subject: Re: Shell "case" command in perl
Message-Id: <memo.970204191027.7271B@zetnet.co.uk>

In article <E51ooo.4AC@nonexistent.com>, abigail@ny.fnx.com (Abigail)
wrote:

> On 3 Feb 1997 11:55:00 GMT, Jan-Patrick Perisse Sys. Admin wrote in
> comp.lang.perl.misc:
> ++ How would a bash "case" look like in perl?
> ++  I've been reading the book and found nothing about it.
>
>
> I prefer to use:
>
>
> foreach ($test) {
>     /foo/     and do {something; last;};
>     /bar/     and do {some other thing; last;};
>     /nut/     and do {bla bla; last;};
>     default things to do;
> }
>
>
> You find more examples on pages 104 and 105 of the book [*].
>
>

That isn't a switch thats an iteration.  Heres a Perl switch :-

CASE: {
	if ($a) {
		#code to do case a
		last CASE; # break
	}
	
	if($b) {
		#code to do case b
		last CASE;
	}
	
	# Ad-infinitem cases, and then ...
	
	die "Your case diverted via Timbuctoo, pick a new airline!\n";
      }
 
Hope this helps.

Regards
Neil

 
	


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

Date: Tue, 04 Feb 1997 12:04:59 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: Re: Trimming Dollar Value
Message-Id: <pudge-ya02408000R0402971205000001@news.idt.net>

In article <01bc12ba$5595f800$61a915a5@cafe>, "Bok Nan Lo"
<support@inklineglobal.com> wrote:

# I'm having hard time with formatting and trimming an amount in a variable.
# 
# e.g. $3.4405
# 
# I just wanted it to be $3.44 rather than four decimal places. How can I get
# it solved?!
# 
# P/S: I want to actually trim it rather than formatting to STDOUT using
# printf().

Try sprintf().

Or $x =~ s/(\.\d\d)(\d?)$/$1/;

#================================================================
Chris Nandor                                      pudge@pobox.com
PGP Key 1024/B76E72AD                           http://pudge.net/
Keyfingerprint = 08 24 09 0B CE 73 CA 10  1F F7 7F 13 81 80 B6 B6


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

Date: Tue, 4 Feb 1997 11:05:27 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Trimming Dollar Value
Message-Id: <n8q7d5.rq1.ln@localhost>

Bok Nan Lo (support@inklineglobal.com) wrote:
: I'm having hard time with formatting and trimming an amount in a variable.

: e.g. $3.4405

: I just wanted it to be $3.44 rather than four decimal places. How can I get
: it solved?!

: P/S: I want to actually trim it rather than formatting to STDOUT using
: printf().


Here's two ways:


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

$_ = '$3.4405';

($trimmed = $_) =~ s/(\.\d\d)\d*/$1/;  # truncate it to two decimal places
print "$trimmed\n";


$trimmed = "\$" . sprintf("%.2f", substr($_, 1)); # round it to two places
print "$trimmed\n";
------------


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 04 Feb 1997 12:24:04 -0600
From: buhr@stat.wisc.edu (Kevin Buhr)
Subject: Re: UNIX-based perl: backgrounding and file descriptors
Message-Id: <vbaiv48mnuj.fsf@mozart.stat.wisc.edu>

--Multipart_Tue_Feb__4_12:24:04_1997-1
Content-Type: text/plain; charset=US-ASCII

Christopher M Wolff <christopher.wolff@nb.rockwell.com> writes:
> 
> 1) Can a background process be launched from within perl?
> I tried using fork,exec,and system, but at best they spawn a child
> process which dies when the parent does.

Consider the attached Perl code.  It spawns a child and then exits.
The child runs forever, mocking you every 10 seconds, until you kill
it.  A "ps" will verify that the parent has, in fact, died, yet the
child lives on!

If this doesn't work for you, your shell may be helpfully killing all
children when it notices the parent has exited.  If so, it's probably
performing the kill on the basis of the process group.  Use of the
Perl "setpgrp" function:

	setpgrp 0,0;  # ha ha!  I'm on my own now!

by the child will pop it into its own process group, and the shell
will probably leave it alone.

> 2) How can I write to a file descriptor specified by number alone?

You shouldn't need to, since the symbolic file handles will be shared
by the parent and child.  That is, if the parent can do:

	print OUTPUT "some output";

before the fork, then *both* the parent and child can do:

	print OUTPUT "more output";

after the fork.

Of course, if you insist, you can use:

	open(SOMENAME, "<&=3") or die;

to open file descriptor 3 as handle "SOMENAME" for reading.  Switch
the "<" to a ">" for writing.  See the documentation for "open" in the
perlfunc(1) manpage for more information.

Kevin <buhr@stat.wisc.edu>

--Multipart_Tue_Feb__4_12:24:04_1997-1
Content-Type: application/octet-stream
Content-Disposition: attachment; filename="forkexample"
Content-Transfer-Encoding: 7bit

#!/usr/bin/perl

$|=1;
print "Parent (pid=$$): Before fork\n";
$child = fork;
if ($child == -1) {
	die "fork: $!\n";
}
if ($child) {
	print "Parent (pid=$$): After fork (child pid=$child), now exiting\n";
	exit(0);
}
while (1) {
	print "Child (pid=$$):  You'll have to kill me!\n";
	sleep(10);
}
exit(0);

--Multipart_Tue_Feb__4_12:24:04_1997-1--


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

Date: 4 Feb 97 17:08:44 +0100 (CET)
From: pcarty@eurokom.ie
Subject: Win32 simple telnet. Not getting login prompt.
Message-Id: <1997Feb4.170844.15733@vms.eurokom.ie>


I've been trying to get telnet_emul.shar
by David Noble (dnoble@ufo.jpl.nasa.gov)
to work on  Win95. The original works fine under Linux

I'm telneting to a DEC Alpha. everything looks OK until
the Username prompt arrives. This isn't matched I suspect because
the socket isn't returning non LF terminated line until it times out.

The original code uses:
        vec($rmask, fileno($handle), 1) = 1;
	($nfound, $rmask) = select($rmask, undef, undef, $endtime - time);
	if ($nfound) {
	    $nread = sysread($handle, $thisbuf, 1024);
	    if ($nread > 0) {

to read the socket. I don't think this construction works on Win32.

Any suggestions gratefully appreciated.

Peter

#################### Usual Socket stuff ################
use Socket;
  ($them,$port) = @ARGV;
    $port = 23 unless $port;
    $them = 'localhost'; # unless $them;
    $sockaddr = 'S n a4 x8';
    $them = "eurokom.ie";

    ($name, $aliases, $proto) = getprotobyname('tcp');
    ($name, $aliases, $port) = getservbyname($port, 'tcp')
        unless $port =~ /^\d+$/;
    ($name, $aliases, $type, $len, $thataddr) = gethostbyname($them);
    $this = pack($sockaddr, AF_INET, 0, "\0\0\0\0");
    $that = pack($sockaddr, AF_INET, $port, $thataddr);

    socket(S, AF_INET, SOCK_STREAM, $proto) || die "socket: $!";
    bind(S, $this) || die "bind: $!";
    connect(S, $that) || die "connect: $!";

    print "Connected OK\n";
    select(S); $* = 1; select(STDOUT);
   
############### Now start to read the socket ###########
while(1) {
$thisbuf = <S>;
&_preprocess;            # Process IAC etc. from telnet_emul.shar.
print STDOUT $thisbuf;
last if $thisbuf =~ /Username:/;   #Here is where the problem is
}

print S "Nobody\r";       # Send an invalid username.
print "Got Username: \n";

print "Client Terminated\n";


###############################################################
sub _preprocess {
    local ($_) = $thisbuf;

    s/\015\012/\012/go; # combine (CR NL) into NL

  if (/Username/) {
   print STDOUT "Got it\n";
   }
       
     while (m/\377/o) {
	# respond to "IAC DO x" or "IAC DON'T x" with "IAC WON'T x"
	if (s/([^\377])?\377[\375\376](.|\n)/\1/o)
            { print "RES "; print S "\377\374$2"; }

	# ignore "IAC WILL x" or "IAC WON'T x"
	elsif (s/([^\377])?\377[\373\374](.|\n)/\1/o) {;}

	# respond to "IAC AYT" (are you there)
	elsif (s/([^\377])?\377\366/\1/o)
            { print "RES1 "; print S "nobody here but us pigeons\n"; }

	else { last; }
    }
    s/\377\377/\377/go; # handle escaped IAC characters

#    $thisbuf = $_;
    m/\n/o; # return value: whether there is a full line or not
}


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

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

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 V7 Issue 893
*************************************

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