[16367] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3779 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 23 09:05:27 2000

Date: Sun, 23 Jul 2000 06:05:13 -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: <964357512-v9-i3779@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 23 Jul 2000     Volume: 9 Number: 3779

Today's topics:
    Re: Activestate PPM not working for Windows? <pmartin1@bigpond.net.au>
    Re: Activestate PPM not working for Windows? (Eric Bohlman)
    Re: Associative Arrays in Perl (Joe Smith)
    Re: help w/ regular expression <bart.lateur@skynet.be>
        How to loop like this - for(a000 ... x999) ??? <rhys.tucker@dtn.ntl.com>
    Re: How to loop like this - for(a000 ... x999) ??? aqutiv@my-deja.com
    Re: How to loop like this - for(a000 ... x999) ??? aqutiv@my-deja.com
    Re: How to loop like this - for(a000 ... x999) ??? <nnickee@nnickee.com>
    Re: Interpreting dev and rdev from stat (in perl) (Joe Smith)
    Re: IO:Socket and Timeout => "5" ? (Colin Keith)
    Re: New to perl, need help (Joe Smith)
    Re: OK, how do I put a variable in a regexp? (Joe Smith)
        perl v. tcl sjfromm@my-deja.com
        Perl vs ColdFusion for Database Oriented Project <davidwebb@MailAndNews.com>
    Re: Problem with NET::FTP -- same problem <nnickee@nnickee.com>
        Q: Finding size in pixels of image files <sfcanci@swcp.com>
    Re: Q: Finding size in pixels of image files <bart.lateur@skynet.be>
    Re: Question on hashes... (Eric Bohlman)
    Re: Question on Reversing the contents of an array.. <snakeman@kc.rr.com>
    Re: Question on Reversing the contents of an array.. <bart.lateur@skynet.be>
    Re: Question on Reversing the contents of an array.. (Colin Keith)
    Re: Read a file into a hash ? (Joe Smith)
    Re: Removing the directory recursivley (Joe Smith)
    Re: replace using regexp (Eric Bohlman)
        Safe.pm question <jdavis@genesiswd.com>
    Re: Saving space in a hash <nospam@nospam.com>
    Re: secure auth trick <bart.lateur@skynet.be>
        Sending mail with formatted text <dguiney@lineone.net>
    Re: Sending mail with formatted text (Colin Keith)
    Re: Sending mail with formatted text <nnickee@nnickee.com>
    Re: Suggestion for syntax change <iltzu@sci.invalid>
    Re: uninitialized variable value? <iltzu@sci.invalid>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 23 Jul 2000 09:28:49 GMT
From: "Peter G. Martin" <pmartin1@bigpond.net.au>
Subject: Re: Activestate PPM not working for Windows?
Message-Id: <397AB99C.AA3EAAB2@bigpond.net.au>



Eric Bohlman wrote:
> 
> Jerry Leventer (9jerry9@my-deja.com) wrote:
> : I have also had problems with the ActiveState PPM on Windows NT4 & 95.
> : I tried,
> :
> :        ppm> search Net::SMTP
> :   and, ppm> install Net::SMTP
> :
> : but, module could not be found (no error msg just blank line with
> : prompt).  Looks like I'll have to download the Net:SMTP module from
> : ActiveState & use makefiles to build it.
> 
> The problem is that Net::SMTP doesn't exist in a vacuum; it's part of a
> bundle called libnet, which includes Net::SMTP, Net::FTP, some other
> protocol-supporting modules and a few modules containing code that's
> common to the rest of them.  "install libnet" should work for you.

There are also a string of other problems. In particular, I found it
sufficiently inconvenient in a Win95 environment, that PPM writes new
module entries into an endless single line.
This eventually motivated me to write a routine that
makes the PPM.xml look like something with a bit more discipline.
I then found that it helps prevent a series of other problems, including
some +supposedly+ coming from SOAP.pm.
I call the subroutine from the bottom of the routine in ppm.bat which
deals with
the "install" option.  i.e....
 .....
    elsif (command($cmd, "in|stall")) {
    ...... various things....
    fixxml();
    }
 ....

And the new subroutine called is

sub fixxml
  {
       print "Fixing PPM.XML file again.\n";
       my $xmlfile = "C:/perl/site/lib/ppm.xml";   # point these to you
own area
       my $tmpfile = "C:/perl/site/lib/ppm.tmp";
       my $xmldata = "";
       undef $/;
       open(PPMXML, "$xmlfile" ) or warn "Couldn't fix PPM.XML (do it by
hand?): $!\n";
       $xmldata = (<PPMXML>);
       close PPMXML;
       $/ = "\n";
       $xmldata =~ s|\>(\<([A-Z]))|\>\n$1|g;
       $xmldata =~ s|\>\</IMPLEMENTATION\>|\>\n\</IMPLEMENTATION\>|g;
       $xmldata =~ s|\>\</SOFTPKG\>|\>\n\</SOFTPKG\>|g;
       $xmldata =~ s|\>\</INSTPPD\>|\>\n\</INSTPPD\>|g;
       $xmldata =~
s|\</PACKAGE\>\</PPMCONFIG\>|\n\</PACKAGE\>\n\n\</PPMCONFIG\>|;
       $xmldata =~ s|PACKAGE\>\n\<PACKAGE|PACKAGE\>\n\n\<PACKAGE|g;
       open(TEMP, "> $tmpfile") or warn "Couldn't write revised ppm.xml
file:$!\n";
       print TEMP $xmldata;
       close TEMP;
       unlink $xmlfile;
       rename $tmpfile, $xmlfile;
}

So far, it seems to work.    ActiveState, last time I checked, wasn't
proposing a change that fixes this problem..


-- 
--peterm   Peter G. Martin  -- Tech. Writer
http://www.zeta.org.au/~peterm +61 2 9818 5094
Mobile: 0408 249 113 peterm@zeta.org.au


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

Date: 23 Jul 2000 12:34:17 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Activestate PPM not working for Windows?
Message-Id: <8leoo9$ok$3@slb0.atl.mindspring.net>

Peter G. Martin (pmartin1@bigpond.net.au) wrote:
: There are also a string of other problems. In particular, I found it
: sufficiently inconvenient in a Win95 environment, that PPM writes new
: module entries into an endless single line.
: This eventually motivated me to write a routine that
: makes the PPM.xml look like something with a bit more discipline.

Be careful there.  In XML-based languages, whitespace outside of markup 
is in general significant; "pretty-printing" an XML document actually 
changes its semantics.  It may be that the current version of PPM ignores 
such whitespace, but future versions might not (if, for example, they 
start reading the XML into a DOM, in which case whitespace in between 
tags will translate into extra text nodes).



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

Date: 23 Jul 2000 10:58:07 GMT
From: inwap@best.com (Joe Smith)
Subject: Re: Associative Arrays in Perl
Message-Id: <8lej3v$25gt$1@nntp1.ba.best.com>

In article <3961ecb8.112361797@news.mn.man.de>,
Martin Doering <doeringm@gmx.de> wrote:
>Hi!
>
>How does perl get/store normal variable values ($xxx) internally? Are
>they stored in an associative array, or are they stored in a more
>C-like manner?

If you have a hankering to look at the sources to perl, I recommend
using "perldoc perlguts" to get a feel for the guts of perl.
	-Joe

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


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

Date: Sun, 23 Jul 2000 09:46:45 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: help w/ regular expression
Message-Id: <chflnss9el6jkudcoevqohggnudsp51a3u@4ax.com>

Eric Bohlman wrote:

>sub extract_phone {
>  my $arg=shift;
>  if ($arg =~ /([-\d\s()]+)$/ and ($1 =~ tr/0-9//)>=7) {
>    ($arg=$1) =~ tr/0-9//cd;
>  }
>  $arg;
>}

The prevalence of lexical variables is getting a bit out of hand. What
happened to $_, which is supposed to be the variable of choice for uses
like this?

 sub extract_phone {
    local $_ = shift;
    if (/([-\d\s()]+)$/ and ($1 =~ tr/0-9//)>=7) {
       $_ = $1;
       tr/0-9//cd;
    }
    return $_;
 }

-- 
	Bart.


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

Date: Sun, 23 Jul 2000 12:15:49 +0000
From: rhys <rhys.tucker@dtn.ntl.com>
Subject: How to loop like this - for(a000 ... x999) ???
Message-Id: <397AE1F5.B7F65F63@dtn.ntl.com>

I'm trying to produce numbers in this sort of format [a-z]\d{3}. I've
tried all sorts of notation to achieve this, even printf, without
success as yet. There must be a straightforward way to do it.

thanks,
rhys


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

Date: Sun, 23 Jul 2000 11:29:07 GMT
From: aqutiv@my-deja.com
Subject: Re: How to loop like this - for(a000 ... x999) ???
Message-Id: <8lektu$nut$1@nnrp1.deja.com>

In article <397AE1F5.B7F65F63@dtn.ntl.com>,
  rhys <rhys.tucker@dtn.ntl.com> wrote:
> I'm trying to produce numbers in this sort of format [a-z]\d{3}. I've
> tried all sorts of notation to achieve this, even printf, without
> success as yet. There must be a straightforward way to do it.
>
> thanks,
> rhys
>

May not be best, but works:

foreach $l (a..z) {
  for $num (0..999) {
     $num = sprintf("%02d", $num);
     print "$l$num\n";
  }
}


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 23 Jul 2000 11:34:22 GMT
From: aqutiv@my-deja.com
Subject: Re: How to loop like this - for(a000 ... x999) ???
Message-Id: <8lel7u$o16$1@nnrp1.deja.com>


>
> May not be best, but works:
>
> foreach $l (a..z) {
>   for $num (0..999) {
>      $num = sprintf("%02d", $num);
>      print "$l$num\n";
>   }
> }

sorry, I seemed to had a typo there. %02d should be %03d.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 23 Jul 2000 07:55:35 -0500
From: Nnickee <nnickee@nnickee.com>
Subject: Re: How to loop like this - for(a000 ... x999) ???
Message-Id: <280166D86582F544.E7DD6DCC295672E3.AD7150F357075C63@lp.airnews.net>

On Sun, 23 Jul 2000 12:15:49 +0000, someone claiming to be rhys
<rhys.tucker@dtn.ntl.com> said:

>I'm trying to produce numbers in this sort of format [a-z]\d{3}. I've
>tried all sorts of notation to achieve this, even printf, without
>success as yet. There must be a straightforward way to do it.

This isn't very elegant (and I'm sure the Gurus will give you much
more elegant ways of doing it, but it didn't produce any warnings for
me... :)

@ALPH = ('a'...'x');
@NUMS = ('000'...'999');
foreach $alph (@ALPH) {
	foreach $num (@NUMS) {
		print "$alph$num\n";
	}
}

HTH
Nnickee



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

Date: 23 Jul 2000 09:00:21 GMT
From: inwap@best.com (Joe Smith)
Subject: Re: Interpreting dev and rdev from stat (in perl)
Message-Id: <8lec75$1tkr$1@nntp1.ba.best.com>

In article <396351e9$0$8301$3c090ad1@news.plethora.net>,
Peter Seebach <seebs@plethora.net> wrote:
>In article <395A3FB5.A8E3FDA5@image.kodak.com>,
>Jim Moore  <jmoore@image.kodak.com> wrote:
>>I am writing a user friendly wrapper for "stat" so that I can see among
>>other information all of the "times" at the same time.  I am looking at
>>what to do with "dev" and "rdev".  I have looked at the Sun answerbook,
>>and really don't seem to understand how to interpret them. Also, in
>>terms of permissions, I can see how you can get some information out of
>>the high order bits, to determine if it is a fifo, block, or character
>>special file.
>
>It is totally unclear how to interpret them.  :)
>
>>What useful information is in dev, and rdev values, do they change (are
>>they dynamic -- i.e. will they change if I look at them at different
>>times of day?)
>
>I have never really looked at rdev, but dev is a magic number; I believe
>it's offset in kernel device table, except on NFS filesystems.

$dev contains the major and minor device numbers for the disk partition
that the file name resides on.

sunos-4.1.4% cat /etc/mtab
/dev/sd0a / 4.2 rw,nosuid,dev=0700 3 1
/dev/sd3a /usr 4.2 rw,dev=0718 1 3
/dev/sd0d /var 4.2 rw,suid,dev=0703 0 2
/dev/sd3h /export/home1 4.2 rw,dev=071f 1 4
swap /tmp tmp rw,nosuid,dev=8700 0 0
salus:/export/home1 /tmp_mnt/home/salus nfs noquota,dev=8203 0 0
sunos-4.1.4% ls -l /dev/sd0a /dev/sd3h
brw-r-----  1 root       7,   0 Sep 15  1993 /dev/sd0a
brw-r-----  1 root       7,  31 Sep 15  1993 /dev/sd3h

If $dev = 0x0700 then it is on device 0x07 unit 0x00 = /dev/sd0a.
If $dev = 0x071f then it is on device 0x07 unit 0x1f (31) = /dev/sd3h.
If ($dev & 0x8000) is set, then it is something else, like an NFS mount.

About the only time I've used $dev is to tell a recursive directory lister
to not process any mount points.

sub wanted {
  ($dev,$ino,$mode,$nlink,$uid,$gid,$rd,$size,$at,$mt,$ct,$bs,$bk) = lstat($_);
  $prune = 1 if ($dev != $topdev) && $xdev;     # Optionally skip mount points
  $prune = 1 if ($dev < 0) && $xnfs;            # Optionally skip NFS dirs
  ...
}

The value for $rdev is meaningless unless the thing in question is the name
of a block-special or character-special device.  For those two items,
$rdev is the 16 or 32-bit value that encodes the major and minor device
numbers.

Here is a section from 'lsf' found at http://www.inwap.com/mybin/
  $dt = sprintf "%8X",$mt;		# Modification time in hex for files
  $dt = "dir"				if -d _; # Directory
  $dt = "b,".($rd>> 8).",".($rd&0xff)	if -b _; # Block dev
  $dt = "b,".($rd>>18).",".($rd&0x3ffff)
                     if -b _ && $rd > 0xffff; # Block dev on 64-bit Solaris-7
  $dt = "c,".($rd>> 8).",".($rd&0xff)	if -c _; # Char dev
  $dt = "c,".($rd>>18).",".($rd&0x3ffff)
                     if -c _ && $rd > 0xffff; # Char dev on 64-bit Solaris-7
  $dt = "p"				if -p _; # Pipe/FIFO
  $dt = "socket"			if -S _; # Socket
  $dt = "door"			if ($mode&0xF000) == 0xD000; # Solaris-2.6
  if (-l _) { may be symlink to directory, symlink to nonexistant file, etc}

The last one I found in /usr/include/sys/stat.h; it is used by Sol26 DNS.
	-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Sun, 23 Jul 2000 11:55:18 GMT
From: ckeith@clara.net (Colin Keith)
Subject: Re: IO:Socket and Timeout => "5" ?
Message-Id: <G2Be5.3$DT4.1206862@nnrp2.clara.net>

In article <BZoe5.7666$Mt.83481@nnrp1.ptd.net>, "Coy" <coy@coystoys.com> wrote:
>Since noone replied to this post...

Urm.. technically I did, though for some strange reason I sent it as a mail 
rather than a followup. The reason you didn't get it was that your mail 
address bounced ... 

"From: ckeith@clara.net (Colin Keith)
To: coy@coystoys.com
Subject: Re: IO::Socket....Timeout => "5"?
Date: Sat, 22 Jul 2000 18:05:02 GMT

>Sorry for the formatting  :(
Werks fer me. Not much help I know, maybe update the
version of IO::Socket ?

perl -mIO::Socket -e 'print $IO::Socket::VERSION;'
1.1603

(I think there are newer versions than that though)"


>after tearing through post after post in every imaginable
>forum dealing w/ Perl,
>I found this:
>Timeout has a problem in the Socket Module version <= 1.1603
>    `perl -e 'use IO::Socket; print "$IO::Socket::VERSION\n"'`
>
>It will hang if quering a non-routable, non-reachable, spoofed, or
>firewalled IP/Ports (that drops packets, not denies them).
>
>I do not know the full specs on this problem, but it seems to be
>the case either way...
>
>So, the way around it was the following:
>    $timeout = 5;
>    $SIG{"ALRM"} = sub {
>        close($socket);
>        print "$target: Timed out connecting to service: $srv_name on port:
> $port";
>    }
>    alarm $timeout;
>
>Not sure why noone knew this or replied..
>works fine know.
>
>thanks anyway.
>
>- Coy
>
>: (yes this is a repost, since noone replied to the last )
>: ( one and I need to get this code done in one week )
>:
>: IO:Socket is used to see that a machine is running
>: its services like it should.
>:
>: Now, I noticed at times, the program would hang
>: in wait (for something)...
>: So, i checked the service by hand (the one it hung on)
>: by telnet 192.168.123.1 <port>
>: Trying 192.168.123.1....
>:
>: (it just hangs here)
>:
>: Now, in my code I have :
>:
>: : foreach $port (@ports) {
>: :     $socket = IO::Socket::INET->new(
>: :                                  PeerAddr => $host,
>: :                                  PeerPort  => $port,
>: :                                  Proto => "tcp",
>: :                                  Timeout    => "5",
>: :                                  Type => SOCK_STREAM)
>: :     or  print "$host: No service on port: $port\n";
>: :
>: :     if ($socket) {
>: :         close($socket);
>: :         print "Service on port: $port\n"
>: :     }
>: : }
>:
>: Isn't Timeout suppose to kill the socket if it doesn't connect?
>: The program just hangs in place forever like the telnet session did.
>: What am I doing wrong ?
>:
>: TIA
>:  -Coy
>:
>:
>:
>
>


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: 23 Jul 2000 11:38:28 GMT
From: inwap@best.com (Joe Smith)
Subject: Re: New to perl, need help
Message-Id: <8lelfk$28hj$1@nntp1.ba.best.com>

In article <87g0pfb047.fsf@limey.hpcc.uh.edu>,
Tony Curtis  <tony_curtis32@yahoo.com> wrote:
>> pshew.. works, but gets darned slow around 25 and up --
>> anyone know of any slick ways to make this sort of thing
>> run faster? (just out of curiosity -- I've seen you guys
>> turn some complex pieces of code into around 15 chars :)
>
>perldoc Memoize, e.g.

solaris-8% perldoc Memoize
No documentation found for "Memoize".

Memoize is not a core module, although it is included in Red Hat Linux.
http://search.cpan.org/search?mode=module&query=Memoize
	-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: 23 Jul 2000 08:10:35 GMT
From: inwap@best.com (Joe Smith)
Subject: Re: OK, how do I put a variable in a regexp?
Message-Id: <8le99r$1psv$1@nntp1.ba.best.com>

In article <zije5.887$Av5.21009@news.kpnqwest.fi>,
Eric Selin <eric.selin@pp.inet.fi> wrote:
>This works:
>$a =~ /14:(.*)\t(.*)/;
>print "$1<br>";
>
>But not this:
>$i = 14;
>$a =~ /^$i:(.*)\t(.*)/;
>print "$i<br>";
>}

Try this:
  $i = 14;
  $a =~ /^$i:(.*)\t(.*)/;
  print "Searching for $i, found '$1' and '$2'<br>";

or
  $i = 14;
  ($first,$second) = $a =~ /^$i:(.*)\t(.*)/;
  print "Searching for $i, found '$first' and '$second'<br>";
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Sun, 23 Jul 2000 12:37:38 GMT
From: sjfromm@my-deja.com
Subject: perl v. tcl
Message-Id: <8leouj$q4t$1@nnrp1.deja.com>

I'm looking for a scripting language to automate simple tasks, such as
asking a user for a few parameters, then running some binary files on
some data and logging what was done, etc.; or providing nice wrappers
for some UNIX commands.

What are the pros/cons of tcl vs. perl?  Right now, I'm using C, which
needless to say isn't right for this job.  Some people I know wrote
such scripts in csh, but the dogma is that csh should be avoided for
scripting.  sh would appear attractive, but its syntax is a little too
idiosyncratic for my taste; and my impression (very shallow, I'll
admit) is that perl and tcl facilities for list manipulation are a
little bit easier to learn than sh's.

I'm also interested in a reference about the different scripting
languages (sh, tcl, perl, etc) that compares their syntax and merits.

Caveat:  I'm not interested in starting a flame war between advocates
of tcl, perl, and sh.

sjfromm


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 23 Jul 2000 08:27:06 -0400
From: David Webb <davidwebb@MailAndNews.com>
Subject: Perl vs ColdFusion for Database Oriented Project
Message-Id: <398460DA@MailAndNews.com>

Hi,

I know that perl is language of choice for CGI but for a database oriented 
project, what should one use?

Can anyone compare the features?

Regards,

------------------------------------------------------------
 Get your FREE web-based e-mail and newsgroup access at:
                http://MailAndNews.com

 Create a new mailbox, or access your existing IMAP4 or
 POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------



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

Date: Sun, 23 Jul 2000 06:45:54 -0500
From: Nnickee <nnickee@nnickee.com>
Subject: Re: Problem with NET::FTP -- same problem
Message-Id: <4BFE36F1DA06511B.E79B638F2B953DB2.78250B6F259046AE@lp.airnews.net>

[ Jeopardectomy performed ]
[ posted & emailed ]

On Fri, 21 Jul 2000 15:58:47 GMT, someone claiming to be
etienno@my-deja.com said:

>  nnickee@nnickee.com wrote:
>> Have you *manually* installed the libnet bundle?  It comes with
>> activestate's perl, but I've noticed that on my systems and on a few
>> other people's systems at least, the modules in it don't get fully
>> installed until you manually install it.

>Hi, i have the same problem. And I tried to install libnet twice but it 
>still tell me the same error...

>Can't locate object method "new" via
>package "Net::Ftp" at [.....]\cgi-bin\ex1\ftp.pl
>line 9.

>-- PPM don't seems to install a full version of NET (libnet)..

PPM has always installed the full libnet bundle for me (once I've
manually installed it), but you never know... have you checked the
activestate bug database to see if someone else has reported the same
error and gotten an answer/fix for it?

If you've already checked that, feel free to send your script directly
to me (as long as it's short... create a new script that gives the
same error -- and please if it has a password in it, *** out the
actual password), or post it here (again, make it a short, fully
contained one that gives the error).  If you send it to me or post it
here, be sure and mention which OS (windows95/98/NT/2K) Perl is
installed to as well as which version of Perl.

>Thanks for answering

You're welcome :)

>info@digitaltango.com

Nnickee



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

Date: Sun, 23 Jul 2000 02:08:53 -0600
From: Sam Cancilla <sfcanci@swcp.com>
Subject: Q: Finding size in pixels of image files
Message-Id: <397AA815.2BCEB35F@swcp.com>

Dear group,

I am looking for a way to find the width and height in pixels of
graphics files using Perl.  A client has a website with huge numbers of
graphics files, mostly jpg but some gif and their web pages have no
height or width attributes in the <img src=...> tags.  I would like to
update their pages using a server-side perl script that I will run
manually on a directory of graphics files at a time.  Is there a module
available, or better yet, is there something built into Perl 5.x that
will allow me to get these numbers?  If you email me responses I will
summarize them here.  Thanks in advance.

Sam Cancilla, sfcanci@swcp.com.



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

Date: Sun, 23 Jul 2000 09:20:40 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Q: Finding size in pixels of image files
Message-Id: <qldlnskbdn4gedduoac85r9sbmuek13f1f@4ax.com>

[posted and mailed]

Sam Cancilla wrote:

>I am looking for a way to find the width and height in pixels of
>graphics files using Perl.  A client has a website with huge numbers of
>graphics files, mostly jpg but some gif and their web pages have no
>height or width attributes in the <img src=...> tags.

Check out the Image::Size module from CPAN. It is a plain Perl module,
although it uses the AUTOLOAD mechanism.

	http://search.cpan.org/search?dist=Image-Size

Installing it should pose little problem, whatever your system, if you
can run make (telnet access); or get the prepared distribution for
Windows from

	http://www.activestate.com/PPMPackages/5.6/zips/Image-Size.zip


If neither of these work for you, remove the dependency on AUTOLOAD from
the source, and the "__END__" line from the "Size.pm" file. Then, all
you need to do is to add this file in a "Image" directory somewhere
where Perl can find it through @INC.

-- 
	Bart.


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

Date: 23 Jul 2000 07:04:49 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Question on hashes...
Message-Id: <8le5eh$fjk$9@slb1.atl.mindspring.net>

Rusty Williamson (rwilliamson@uno.gers.com) wrote:
: Oh BTW... local allows a data structure to be seen by the functions called
: from the function its defined in, yes.  'my' on the other hand can only be
: seen with the function it's called in -- have I got that wrong?  I need my
: structure to be seen by stuff higher on the stack.  Perhaps I have this
: wrong... or perhaps it's considered bad practice?  My PERL is very rusty (no
: pun intended).

<pedantry>The language is Perl.  The interpreter is perl.  Nothing is 
PERL.</pedantry>

Your understanding isn't quite correct.  Lexical variables are scoped to
the innermost block they're declared in (a file is regarded as a block). 
Thus, if you want a lexical variable to be visible to several subs but not
to any other code, you can enclose the subs' definitions in a block that
begins with the declaration of the variable: 

{my $shared;

 sub first {
 ...
 }

 sub second {
 ...
 }
}

Now first() and second() can access $shared, but no other code can.  
$shared is in fact persistent between invocations of the subs, since its 
scope is the same as that of the subs' definitions and hence it never 
goes out of scope.



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

Date: Sun, 23 Jul 2000 07:05:04 GMT
From: "DS" <snakeman@kc.rr.com>
Subject: Re: Question on Reversing the contents of an array..
Message-Id: <AOwe5.8421$t%4.90180@typhoon.kc.rr.com>

Cool Thanx Guys. Helped alot. I saw the error in my ways :). I ended up
using this.

open(DAT,data.dat) or die("Could not open file!");
@raw = <DAT>;
@raw = reverse(@raw);
close(DAT);

DS

"DS" <snakeman@kc.rr.com> wrote in message
news:DWue5.7798$t%4.89417@typhoon.kc.rr.com...
> Hello all-
>    I have a question on reversing the contents of an array. What I am
trying
> to do is read a data file and then print the last line of the data file
> first. I think I may be using this "reverse" comand totally wrong but it
> sounds like what I needed. This is what I have so far:
>
> open(DAT,data.dat) or die("Could not open file!");
> @raw = <DAT>;
> reverse(@raw);
> close(DAT);
>
> foreach $line (@raw) {
>     chomp($line);
>     print "$line\n";
> }
>
> My data file  is like this:
>   item1|item2|item3|item4
>   item1|item2|item3|item4
>   item1|item2|item3|item4
> and so on.....
>
> Can't you use the "reverse command on this array?
>
> Thanx
> DS
>
>




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

Date: Sun, 23 Jul 2000 11:02:08 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Question on Reversing the contents of an array..
Message-Id: <c5klns8rejdeg0q116bmbqeegdor27sv78@4ax.com>

DS wrote:

>@raw = <DAT>;
>@raw = reverse(@raw);

Or:

	@raw = reverse <DAT>;

-- 
	Bart.


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

Date: Sun, 23 Jul 2000 12:23:57 GMT
From: ckeith@clara.net (Colin Keith)
Subject: Re: Question on Reversing the contents of an array..
Message-Id: <xtBe5.5$DT4.1210115@nnrp2.clara.net>

In article <AOwe5.8421$t%4.90180@typhoon.kc.rr.com>, "DS" <snakeman@kc.rr.com> wrote:

Dumb question, but in your original post you said:

>"DS" <snakeman@kc.rr.com> wrote in message
>news:DWue5.7798$t%4.89417@typhoon.kc.rr.com...

>> to do is read a data file and then print the last line of the data file

If this is really all you want to do, then wouldn't it be easier to just 
do this rather than pull a (large?) array into memory and reverse it?

maia% perl -w -Mstrict
open(FH, "<ns4.css") || die "ick: - $!";
$_ = <FH> until(eof(FH));
print;

Col.


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: 23 Jul 2000 12:55:58 GMT
From: inwap@best.com (Joe Smith)
Subject: Re: Read a file into a hash ?
Message-Id: <8leq0u$2e8e$1@nntp1.ba.best.com>

In article <MPG.13dd297feb3984b098abda@nntp.hpl.hp.com>,
Larry Rosler  <lr@hpl.hp.com> wrote:
>In article <k8ektozh.fsf@macforce.sumus.dk> on 17 Jul 2000 23:40:18 
>+0200, Jakob Schmidt <sumus@aut.dk> says...
>> Far as I can see there's no consensus for checking the success of close()
>> (on filehandles). Maybe because finding that it doesn't is just so
>> embarrassing that you don't even want to know?
>
>Closing a file opened for reading is pointless, unless another process 
>or later in this process intends to access it.

Closing a file opened for reading is good programming, otherwise you
could run out of available file descriptors.

I'm willing to give Larry the benefit of doubt.  I believe he meant
"Checking the return value from close() on a file opened for reading is
pointless".  
	-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: 23 Jul 2000 11:05:06 GMT
From: inwap@best.com (Joe Smith)
Subject: Re: Removing the directory recursivley
Message-Id: <8lejh2$262a$1@nntp1.ba.best.com>

In article <8k2r16$g05$1@nnrp1.deja.com>,  <thgibbs@my-deja.com> wrote:
>Also, in Unix you might want to add the -f flag to prevent
>prompting for files without write permission.
>
>rm -rf * will remove all files in all directories and all directories.

But will not delete any directories that start with a period, such
as ".ssh" and ".elm".
	-Joe
--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: 23 Jul 2000 07:10:58 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: replace using regexp
Message-Id: <8le5q2$fjk$10@slb1.atl.mindspring.net>

suj_h (suj_h@yahoo.com) wrote:
: I need to process a text file that has this format:
: ...
: some string here -> some more string here
: ...
: I want to keep only what comes before "->" and drop everything else in
: the output. Could someone point out why this code doesn't do that?
: 
: open(infile, "data") or die "Can't open infile";

You should include $! in your error message so you can find out *why* you 
can't open the file.

: while($line=<infile>){
:  if($line =~ /^(.+)->(.+)$/){

Everything in your regex after the '->' is superfluous.

:   print "\1\n";

That should be '$1', not '\1'.  You need to (re-)read perlre, which will 
tell you that the backslash-digit form is used *only* in regular 
expressions themselves, with a special, but deprecated, dispensation 
given for replacement strings in the 's//' operator.

:  }
: }
: close(infile);


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

Date: Sun, 23 Jul 2000 08:29:19 GMT
From: Jeff Davis <jdavis@genesiswd.com>
Subject: Safe.pm question
Message-Id: <500D0C5E.71EDE7D0@genesiswd.com>

I would like to be able to run code in a container using Safe.pm which
has access only to a certain set of builtin functions (like print) and a
set of my own subroutines.

Every time I try to use permit_only() it seems to work for builtins, but
it does not accept my subroutine as an operator. If I use share after
that to try to include my sub, than it doesn't work (I guess because the
mask is already set). If I use share and no permit_only then I can't
restrict the use of builtins that are allowed by default in Safe.pm. My
question is, how can I execute a piece of code where only print() and
public_subroutine() (which is a sub I made) are allowed, and no others?
(this is an example, in reality I would use more). Below I have included
an example of what I tried, after exhaustively browsing perl docs.

#!/usr/bin/perl -w
use Safe;
sub issafe();
$cpt = new Safe;
$cpt->permit_only('issafe','print'); # 'error: issafe not operator' when
I try to run
$r = $cpt->reval("issafe();");
if($r) { print "container executed"; }
print "end\n";
sub issafe() {
    print "safe\n";
}


Thanks,
    Jeff Davis



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

Date: 23 Jul 2000 07:51:57 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: Saving space in a hash
Message-Id: <8le86t$oc6$0@216.155.33.54>

In article <3978410c.43197167@news.newsguy.com>, kcivey@cpcug.org 
(Keith Calvert Ivey) wrote:

 | The WebDragon <nospam@nospam.com> wrote:
 | >Russ Jones <russ_jones@rac.ray.com> wrote:
 | 
 | > | I'm building a hash that contains the same line of data, referenced
 | > | three different ways, like this:
 | > | 
 | > | 	$snmp{$ip}    = $snmp_info;
 | > | 	$snmp{$dns}   = $snmp_info;
 | > | 	$snmp{$alias} = $snmp_info;
 | [snip]
 | 
 | >how about a simple HoL ? 
 | >
 | >    $snmp{$ip} = [ $dns, $alias, $snmp_info ];
 | 
 | Presumably the idea is to be able to access the data in
 | $snmp_info by IP address, DNS name, or alias, whichever you
 | happen to have.  With your way, you can't get the data (without
 | searching through the whole hash) unless you know the IP
 | address.

also true, but it's just a suggestion for approach.. ultimately it can 
be organized any way he likes. The real question here is how he plans to 
access and reference the data in question, and he hasn't responded to 
that yet...

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: Sun, 23 Jul 2000 11:15:55 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: secure auth trick
Message-Id: <5lklns47i9f9blgn0s1nkb71mhc8ai86ph@4ax.com>

Robin Bank wrote:

>That way when someone tries to access the file through http, it tries TO RUN
>THE SCRIPT and causes an internal server error...

>OR, IF IT IS A VALID program, stores the output
>rather than the source code. This is awesome...

It's only secure for people not having access to your machine. If, for
example, you have web space with an ISP on a machine that is shared
between you and many other people, each and every one of those can read
your file through their FTP connection, I would think.

Butn here's a variation:

	#!/usr/local/bin/perl -w
	print <<'EOT';
	Content-Type: text/plain

	bleh bleh bleh!
	__END__
	Your data comes here...
	etc.


All you need to do, is open the file, skip all lines until you get at
the "__END__" line, and there you can start reading the actual data.

	while(<FILE>) {
	    last if /^__END__$/;
	}

	while(<FILE>) {
	    print "Actual data: $_";
	}

-- 
	Bart.


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

Date: Sun, 23 Jul 2000 12:37:27 +0100
From: "David Guiney" <dguiney@lineone.net>
Subject: Sending mail with formatted text
Message-Id: <8leld4$ld5$1@supernews.com>

I am witten a script to send out mail to recipients in a mailing list but so
far the message body is simple text.

Can anybody give me any pointers on spicing this up a bit ie.
bold,italics,font size etc. Can I use HTML format - if so what changes would
I need to make?

Thanks in anticipation for any help in this matter.

David




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

Date: Sun, 23 Jul 2000 12:09:19 GMT
From: ckeith@clara.net (Colin Keith)
Subject: Re: Sending mail with formatted text
Message-Id: <PfBe5.4$DT4.1208715@nnrp2.clara.net>

In article <8leld4$ld5$1@supernews.com>, "David Guiney" <dguiney@lineone.net> wrote:
>I am witten a script to send out mail to recipients in a mailing list but so
>far the message body is simple text.
>
>Can anybody give me any pointers on spicing this up a bit ie.
>bold,italics,font size etc. Can I use HTML format - if so what changes would
>I need to make?

*searches down the back of the sofa for the relevance to this group* :)
(best I can come up with)

Perl's print and printf statements will allow you to print any characters 
you want though if you are using text that contains double quotation marks, 
you need to remember to escape them, ala \", (assuming you're double quote
enclosing your text so you can use embedded variables and newline 
characters, I.e ("Dear $name,\n")

If you want to use HTML you may find that the CGI module will be helpful for 
URL encoding of strings and the addition of MIME attachments can be handled 
by MIME::* modules. (Remember that send HTML in e-mails should only be done 
if you're recipients are able to handle it HTML looks icky in a mail program 
that doesn't decode it, and doubles the size of the mail for no reason.)

You may also want to use the Mail::Sendmail module to send your mail ... 

But that's about the closest that perl gets to your question. Yes, you can 
send anything you want but this isn't the group to ask about that, its the 
forum to ask for help with problems you're encountering doing so. (Once 
you've read the FAQ's of course)

Col.


---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC


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

Date: Sun, 23 Jul 2000 08:03:51 -0500
From: Nnickee <nnickee@nnickee.com>
Subject: Re: Sending mail with formatted text
Message-Id: <AA4ADA60E0BC2EE3.6AA0D1D36E5844AC.039748F4BC649736@lp.airnews.net>

On Sun, 23 Jul 2000 12:37:27 +0100, someone claiming to be "David
Guiney" <dguiney@lineone.net> said:

>I am witten a script to send out mail to recipients in a mailing list but so
>far the message body is simple text.

>Can anybody give me any pointers on spicing this up a bit ie.
>bold,italics,font size etc. Can I use HTML format - if so what changes would
>I need to make?

You sure can.

Change your message body to html format (start it with <html> ....
whatever ... <tags> .... </html>

And add a couple more headers into the header section of the email

(the following works with NET::SMTP:

	  $smtp->datasend("Content-Type: text/html\n");
	  $smtp->datasend("Content-Transfer-Encoding: 7-bit\n");

)


HTH
Nnickee



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

Date: 23 Jul 2000 11:16:56 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Suggestion for syntax change
Message-Id: <964349287.4445@itz.pp.sci.fi>

In article <qu1jnsshg2nofnt7u27v7o5vupnnvnjjuc@4ax.com>, Bart Lateur wrote:
>That's just an example that model and implementation need not agree.
>Perl not doing proper DWIM for @item[2 .. -2] because of how it's
>implemented, seems too primitive an argument to me.

The problem is that we'd end up with the sort of evilness already
manifest in do/while loops, which behave in a most unexpected manner
if the do{} isn't the only expression in the body of the statement.

In your case, which of these should DWIM and which should not?

  @foo[2 .. -2]
  @foo[2 .. -2, ()]
  @foo[0 || 2 .. -2]
  @foo[@bar = 2 .. -2] 
  @foo[grep 1x$_ !~ /^(11+)\1+$/ => 2 .. -2]

In particular, if the third expression should be identical to the
first, should replacing 0 with a known-to-be-false variable make a
difference?  (It does for do/while.)


Now don't get me wrong, I do agree there should be some way to get
middle slices of unknown lists.  I just don't think yours is a good
solution to the problem.  The best alternative I can think of so far
would be a special variable locally set to the maximum index whenever
[EXPR] is evaluated.  That'd be no weirder than $1 and friends.

The only problem would be choosing which one to use.  $# looks like
the obvious choice, but besides having an existing - if deprecated -
meaning, it has also been suggested as an index counter in foreach
loops (and map/grep too?).

Oh, and while we're adding features, how about %foo = %bar{@keys} ?

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method."  -- Abigail
Please ignore Godzilla and its pseudonyms - do not feed the troll.



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

Date: 23 Jul 2000 11:32:44 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: uninitialized variable value?
Message-Id: <964351570.7423@itz.pp.sci.fi>

In article <slrn8njoro.vcg.abigail@alexandra.foad.org>, Abigail wrote:
>M.J.T. Guy (mjtg@cus.cam.ac.uk) wrote on MMDXVII September MCMXCIII in
><URL:news:8lc8nj$6ir$1@pegasus.csx.cam.ac.uk>:
>() Abigail <abigail@foad.org> wrote:
>() >
>() >Here's one way to test it:
>() >
>() >    eval 'local $^W = 1; "$certain_variable"';
>() >    if ($@ =~ /^Use of uninitialized value in string/) {
>() >        # Value is unitialized
>() >    }
>() 
>() Eh?   What are you expecting to see in $@ ?
>
>Did you try?

I just did:

  bash-2.01$ cat foo.pl
  eval 'local $^W = 1; "$certain_variable"';
  if ($@ =~ /^Use of uninitialized value/) {
      print "Well I'll be..\n";
  } else {
      print "Thought so!\n";
  }

  bash-2.01$ perl foo.pl
  Use of uninitialized value at (eval 1) line 1.
  Thought so!

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method."  -- Abigail
Please ignore Godzilla and its pseudonyms - do not feed the troll.



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

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 3779
**************************************


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