[7268] in Perl-Users-Digest
Perl-Users Digest, Issue: 893 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 20 06:08:50 1997
Date: Wed, 20 Aug 97 03:00:25 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 20 Aug 1997 Volume: 8 Number: 893
Today's topics:
Re: *Really* dynamic function loading? (M.J.T. Guy)
another regex <gland@ccs.neu.edu>
Re: Beginner problems <jbc@west.net>
Re: Beginner problems (M.J.T. Guy)
Re: Block parameters <ghowland@hotlava.com>
Re: Doubt using PERL and NT <pwalker@pcfoods.com>
Re: efficient editing (M.J.T. Guy)
FORM SUBMIT on PerlIS doesn't work ? <pegit.swedmap@mbox300.swipnet.se>
Re: global string searches (M.J.T. Guy)
Re: How to access 3D hash keys through reference? (M.J.T. Guy)
Re: naming arrays (Jim Trocki)
Re: naming arrays (M.J.T. Guy)
Re: Number conversion help <rovf@earthling.net>
Re: Pattern repacement with variables question <ajohnson@gpu.srv.ualberta.ca>
Perl 5 client/server <karl-ake.eriksson@edt.ericsson.se>
Perl and OLE Automation <anc@sec.cpg.sony.co.jp>
Re: Perl Win95 <gdunn@lis.net.au>
Re: Q: Assignment by symbolic reference??? (David Bauman)
Re: readig a file into an array <rovf@earthling.net>
Re: regexp C library <usenet-tag@qz.little-neck.ny.us>
Re: Retrieving graphic dimensions through PERL w/o actu (Iain Chalmers)
Re: Round Function (M.J.T. Guy)
Still not solved (was: Pattern repacement with variable <rovf@earthling.net>
Re: Unix pwd (Lack Mr G M)
Wanted: list of known bugs <martt@elsevier.nl>
Re: writing to a file (Jim Trocki)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Aug 1997 08:02:38 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: *Really* dynamic function loading?
Message-Id: <5te8au$rqv$1@lyra.csx.cam.ac.uk>
Dan Zerkle <zerkle@cs.ucdavis.edu> wrote:
>Hmmm. The Perl FAQ seems to be inaccessible. I guess I'll have
>to post.
I don't believe that. Apart from the copy at perl.com, there's a copy
in the documentation which comes with every modern version of perl,
there are copies (in five different formats) on every CPAN site around
the world, or (since it has been posted here) you could always find it
via DejaNews. You mean _none_ of these resources were available?
>I want to do some very late loading and execution of subroutines,
>but I don't know if it is possible. Here's what I want:
And it isn't actually a FAQ after all, so if you'd done the research
suggested above, you'd have wasted your time :-(. But fortunately
Abigail has already answered with the magic word "AUTOLOAD".
Mike Guy
------------------------------
Date: 20 Aug 1997 05:58:47 GMT
From: Greg Land <gland@ccs.neu.edu>
Subject: another regex
Message-Id: <5te12n$hro$1@camelot.ccs.neu.edu>
Ok... once again I am faced with a few lines of code and my problem
is dealing with regexes. I have a section that looks like this:
<TR>
<TD>
<P><CENTER>1995</CENTER>
</TD><TD>
<P>some, one
</TD><TD>
<P>Someone@somewhere.com
</TD></TR>
<TR>
What I need is to make it look like this:
<TR>
<TD>
<P><CENTER>1995</CENTER>
</TD><TD>
<P>some, one
</TD><TD>
<P><a href="Someone@somewhere.com">Someone@somewhere.com</a>
</TD></TR>
<TR>
Any help would be apperaciated.
Thanks in advance
Greg
------------------------------
Date: 20 Aug 1997 01:00:01 -0700
From: John Callender <jbc@west.net>
To: equi@herald.infi.net
Subject: Re: Beginner problems
Message-Id: <33FAA4CC.9487ED07@west.net>
Dan wrote:
> #!/usr/local/bin/perl -w
> print("My name is Yon Yonson,\n");
> print("I live in Wisconsin,\n", "I work in a lumbermill there.\n");
>
> Then, I opened the perl 5 program and typed perl test.pl and hit enetr
> and nothing.
> Then, I typed C:\perl5\bin\perl test.pl and it said I had a bunch of
> syntax errors.
1. The script itself looks okay to me.
2. The DOS/Windows perl implementation doesn't understand the
#!/usr/local/bin/perl -w
line. That's a Unix convention. It doesn't hurt, since it's commented by
the initial # character, but it doesn't help, either.
3. I'm guessing you got into trouble at the part where you said you
"opened the perl5 program". Would I be correct in guessing that you
double-clicked on it in the Windows Explorer, or invoked it via
Start:Run, or something like that? And then it gave you a blank window
with a blinking cursor, where you proceeded to type in
"C:\perl5\bin\perl test.pl"?
And then you got an error message that looked something like:
c:\perl5\bin\perl test.pl
Backslash found where operator expected at - line 1, near "perl5\"
syntax error at - line 1, near "perl5\"
Backslash found where operator expected at - line 1, near "bin\"
If so, you're real close. What happened (I think) was that you fired up
the perl command interpreter, which gave you a blank window, expecting
you to pass it a script to execute. But you see, you've already saved
the script in your test.pl file, so you don't need to do that. The line
C:\perl5\bin\perl test.pl
needs to be typed into a blank window representing the **DOS** command
interpreter (or whatever they call it nowadays). Here's a way to tell:
What was in the title bar of the window where you typed the line above?
"Perl"? Or "MS-DOS Prompt"? You want the latter, not the former.
The way I run a Perl script under Windows 95 is to use the Start menu to
run the "DOS command prompt" program, or just bring up the Start:Run...
dialog and type "command" into it, and THEN type
C:\perl5\bin\perl test.pl
(or whatever) in the window that comes up and hit Enter. (Note: test.pl
should be in the current directory.) Give it a try and let me know what
happens, okay?
Good luck!
P.S. The reason this sounded so familiar to me is that a co-worker of
mine recently succumbed to my prostletyzing and installed Perl on her
Windows 95 machine, and she had the same problem when she tried to run
her first hello.pl script.
It makes me feel warm and fuzzy to think of another Wintel machine
lighting up with Perl-ness. It's like that scene in "It's a Wonderful
Life" when Clarence gets his wings. If/when you actually get your Yon
Yonson script to print to your screen, I'm sure I'll hear a bell ringing
in the distance.
--
John Callender
jbc@west.net
http://www.west.net/~jbc/
------------------------------
Date: 20 Aug 1997 08:25:10 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Beginner problems
Message-Id: <5te9l6$spg$1@lyra.csx.cam.ac.uk>
In article <33FAA4CC.9487ED07@west.net>, John Callender <jbc@west.net> wrote:
>2. The DOS/Windows perl implementation doesn't understand the
>
>#!/usr/local/bin/perl -w
>
>line. That's a Unix convention. It doesn't hurt, since it's commented by
>the initial # character, but it doesn't help, either.
Not quite true - Perl still processes the line and acts on the -w flag.
So the line is worth including.
Mike Guy
------------------------------
Date: Wed, 20 Aug 1997 10:12:49 +0200
From: Gary Howland <ghowland@hotlava.com>
To: Thad Welch <tw36027@glaxowellcome.com>
Subject: Re: Block parameters
Message-Id: <33FAA701.765F@hotlava.com>
Thad Welch wrote:
>
> I've noticed that some built-in perl functions like (sort, grep) can
> take
> a Block parameter. ie
> sort { $a->date <=> $b->date } @objects.
>
> I know you can pass a 'sub {}' parameter, but using a block looks
> better in my opinion.
>
> So, if there anyway to pass a Block as a parameter?
Yes - declare your function with a prototype containing '&'.
For example, here is the reimplementation of grep taken from the camel
book:
sub mygrep (&@)
{
my $coderef = shift;
my @result;
foreach $_ (@_)
{
push (@result, $_) if &$coderef;
}
@result;
}
One for the FAQ I guess.
Gary
------------------------------
Date: Tue, 19 Aug 1997 23:08:48 -0500
From: Paul Walker <pwalker@pcfoods.com>
Subject: Re: Doubt using PERL and NT
Message-Id: <33FA6DD0.5BBE@pegasus.us.dell.com>
Alex wrote:
>
> Not sure if anyone replied to this, but I don't think you can do what you
> are trying to. UNC names may work from the command prompt (95 and NT only)
> but I haven't found a way to use them in perl scripting.
>
> The alternative I use is to 'net use' a drive to a remote machine and then
> do this instead. If you are switching between multiple machiens, you could
> always do something clever like connecting a virtual drive to a machine on
> the fly, referring to it as a drive letter to read/write your files, and
> then deleting it at the end.
>
> Regards,
>
> Alex
Alex,
I opt to not to map drives. We run lots of scripts from
the scheduler on a server and drive letter mgmt can be an issue.
I found that using normal unix file path notation works fine
when running on nt. All my readdir's, stats, opens, etc use
//server/share/directory (ala UNC's) and have yet to have a problem.
The only problem I have seen is when using system(). If
I wish to pass a true unc name I have to escape each \. Looks
strange but it does work.
Hope that gives something to try anyway.
Paul
>
> rcosta@cenapad.unicamp.br wrote in article <869769873.2629@dejanews.com>...
>
> > I have a matter that I can't solve. I'm using PERL for Windows NT and
> >IIS Web Server. I have my page on a server where IIS is running and I
> >want to see some files that are on other computer. These computers belong
> >to the same network. I'm using the following command on my PERL script:
> >
> > $var = `dir \\\\another_computer\\sharename`;
------------------------------
Date: 20 Aug 1997 08:54:57 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: efficient editing
Message-Id: <5tebd1$j3$1@lyra.csx.cam.ac.uk>
Dean Hoover <dhoover@textwise.com> wrote:
>I'm trying to figure out the best way to change:
> \ to \\ and | to \V and & to \A
>
>in one fell swoop, efficiently.
s/([\\|&])/+{qw:\ \\ | \V & \A:}->{$1}/ge;
Dunno if that's the most efficient, or even the most cryptic.
Mike Guy
------------------------------
Date: Wed, 20 Aug 1997 11:00:35 +0200
From: Pinne <pegit.swedmap@mbox300.swipnet.se>
Subject: FORM SUBMIT on PerlIS doesn't work ?
Message-Id: <33FAB233.4F6D@mbox300.swipnet.se>
Hi,
Thanks everyone for the tips so far.
I am t still trying to get my PerlIS
to work on NT S 4.0 w IIS 3.0.
I have a script that creates a form with
some submit buttons on it.
It works ok with Perl.exe, but when i click
the buttons using PerlIS it seems like all the
information isn't passed on to the Perl interpreter.
Any suggestions ?
------------------------------
Date: 20 Aug 1997 09:12:29 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: global string searches
Message-Id: <5tecdt$182$1@lyra.csx.cam.ac.uk>
Matt Wolak <Mwolak@wesleyan.edu> wrote:
>I am currently writing a program that extracts info from pdb (a chemical
>format) files. Is it 'legal' to search in the same string you are doing
>a global search on ie:
>
>while($str =~ /whatever(.{3})/g){
> $temp = $1;
> if($str =~ /somethingelse $temp/){ #Not really what I'm tring
>to do, just an example
> print("yes")
> }
>}
>
>or does this mess up the global searches pointer?
This particular example would not. There is one pointer maintained
per string, which may be read / set using the "pos" function. The pointer
is set to undef whenever the string is updated, and set suitably whenever
an m//g is obeyed in a scalar context. An m// (without g) leaves it
unaffected.
Mike Guy
------------------------------
Date: 20 Aug 1997 08:48:09 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: How to access 3D hash keys through reference?
Message-Id: <5teb09$c1$1@lyra.csx.cam.ac.uk>
In article <33F9DDAA.6F76@sdt.com>, Kerr Tung <kerr_tung@sdt.com> wrote:
>Hi all,
>
>I build a 3D hash. $table{$user}{$cur_view}{$file} = $x; I would like to
>access all the 3 keys through dereferencing in a sub.
Go at it step by step:
%table is a 3D hash, i.e. a hash each of whose values is a reference to a
hash each of whose values is a reference to a hash.
$table{$user} is a reference to a hash, each of whose values is a
reference to hash.
%{$table{$user}} is a hash, each of whose values is a reference to hash.
$table{$user}{$cur_view}, which is an abbreviation for
${$table{$user}}{$cur_view} or for $table{$user}->{$cur_view},
is a reference to a hash.
%{$table{$user}{$cur_view}} is a hash.
$table{$user}{$cur_view}{$file} (which is an abbreviation for various
things you can work out for yourself) is the final value wanted.
(Has that made things clearer? I'm not so sure :-( )
Applying this to the example:
>#call the sub to print
>&print_keys(\%table);
>
>sub print_keys {
> my($hash_ref) = @_;
> my $user;
> my $view;
> my $file;
>
> foreach $user (sort keys %$hash_ref) { #this works
> print "user: $user\n";
> foreach $view (sort keys ???){ # how do I dereferce this one?
my $user_hash = $hash_ref->{$user}; # reference to 2d hash
foreach $view (sort keys %$user_hash){
or
foreach $view (sort keys %{$hash_ref->{$user}}){
> print "view: $view\n";
> foreach $file (sort keys ???){ #how do I dereference this one?
my $view_hash = $user_hash->{$view}; # reference to hash
foreach $file (sort keys %$view_hash){
or
foreach $file (sort keys %{$user_hash->{$view}}){
> print "file: $file\n";
> }
> }
> }
>}
Mike Guy
------------------------------
Date: 20 Aug 1997 07:10:54 GMT
From: trockij@transmeta.com (Jim Trocki)
Subject: Re: naming arrays
Message-Id: <5te59u$f1j$1@palladium.transmeta.com>
In article <33FA43CA.2854@hackberry.chem.niu.edu>,
Darin Burleigh <burleigh@hackberry.chem.niu.edu> wrote:
>MAHANTA girish wrote:
>>
>> Hello!
>>
>> Can I know how to go about this:
>>
>> I have a large number of arrays named: @bw00, @bw01, .... @bw050
>> Inside the program I want to reference the arrays dynamically, with help of
>> the numbers following the @bw string. Say @bw$n where $n has the subscript
>> of the array I want to reference, without having to wrtie @bw00 explicitely.
>>
>> Is there any way I can do this? I appreciate any help.
>>
>> Regards,
>>
>> Girish.
>
>@{bw$n}
This doesn't work.
Girish, it sounds like you would probably be better off implementing
this as an array or arrays, where you could address arrays separately.
Here's a brief example:
@{$bw[0]}=(2,4,6,8);
@{$bw[1]}=(1,3,5,7);
print "@{$bw[0]}\n";
print "@{$bw[1]}\n";
Have a look at the "perllol" man page.
Jim Trocki
Computer System and Network Engineer
Transmeta Corporation
Santa Clara, CA trockij@transmeta.com
--
Jim Trocki
Computer System and Network Engineer
Transmeta Corporation
Santa Clara, CA trockij@transmeta.com
------------------------------
Date: 20 Aug 1997 07:10:41 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: naming arrays
Message-Id: <5te59h$q9l$1@lyra.csx.cam.ac.uk>
Darin Burleigh <burleigh@hackberry.chem.niu.edu> wrote:
>
>@{bw$n}
That's a syntax error (unless you've declared the subroutine bw).
You want
@{"bw$n"}
And in any case, don't do it this way - follow Tad's advice.
Mike Guy
------------------------------
Date: 20 Aug 1997 11:13:53 +0200
From: Ronald Fischer <rovf@earthling.net>
Subject: Re: Number conversion help
Message-Id: <xz2en7pcj3i.fsf@uebemc.siemens.de>
>>>>> On Tue, 19 Aug 1997 08:52:20 -0700
>>>>> "JG" == John Grimm <ken1@earthlink.net> wrote:
JG> I need to translate a number like -1.7 to -017000 or something like 9.3
JG> to +093000
($formatted_number = sprintf("%6.4f",$your_number)) =~ tr/.//d;
--
Ronald Fischer (rovf@Earthling.net) (PGP public key available)
http://ourworld.compuserve.com/homepages/ronald_fischer/
[When posting a followup, mailing a courtesy copy is fine, provided it is
clearly marked as such.]
------------------------------
Date: Wed, 20 Aug 1997 00:36:34 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Pattern repacement with variables question
Message-Id: <33FA8262.72CFA3AE@gpu.srv.ualberta.ca>
Russ Allbery wrote:
>
> [ Posted and mailed. ]
>
> Vince Busam <vincent.busam@ngc.com> writes:
>
> > $test = "one two";
> > $match = '^([^ ]+) +([^ ]+)';
> > $replace = '$2 $1';
> > $test =~ s/$match/$replace/;
> > print "$test\n";
>
> > The output is:
> > $2 $1
>
> > instead I'd like to see:
> > two one
>
> Change the substitution line to:
>
> $test =~ s/$match/$replace/ee;
that won't work on my perl unless $replace is
changed to:
$replace = '"$2 $1"';
regards
andrew
------------------------------
Date: Wed, 20 Aug 1997 07:50:34 +0200
From: Karl-Ake Eriksson <karl-ake.eriksson@edt.ericsson.se>
Subject: Perl 5 client/server
Message-Id: <33FA85AA.E096FE18@edt.ericsson.se>
"Programming Perl" (Perl 5 edition) describes very simple
internet TCP clients and servers on page 349 - 350. When a client
connects the server returns the output of the Perl function
localtime.
I have tried to return the output of a Unix command by
backticking it (e.g. `/usr/bin/date`). For all variations
of this the server terminates with a core dump when trying
to execute the Unix command.
Is this a bug in Perl (version 5.004_01) or is this kind of
thing not allowed from a network server ?
Thanks for any advice
Karl-Ake Eriksson
--
-------------------------------------------------------------------------
Karl-Ake Eriksson Phone: +46 8 726 2922
LM Ericsson Data AB Fax: +46 8 721 7131
EDT/N/DMU Unixcenter Mobile: +46 70 774 3771
Gotalandsvagen 230 Memo: ERI.EDT.EDTKEN
S-125 82 Stockholm, Sweden Email: karl-ake.eriksson@edt.ericsson.se
-------------------------------------------------------------------------
------------------------------
Date: 20 Aug 1997 08:06:12 GMT
From: "Andrew Collins" <anc@sec.cpg.sony.co.jp>
Subject: Perl and OLE Automation
Message-Id: <01bcad40$b5c85ad0$d28b002b@se1ql56>
I am using Perl on NT for accessing some database applications to process
the data and communicating via a set of OLE Automation objects and the
oleauto package. The single documentation page that I have states that if a
method or property returns an embedded OLE object then perl will
automatically treat it as a perl object itself... the cited example is....
$object->dad->grandad->tell_old_war_stories();
This is exactly what I want, but how is this implemented, as far as I
understand the OLE Automation interface has a restricted set of data types,
so it can only return IUnknown or IDispatch as pointers as far as I am
aware... anyone know about this magic?
On a similar vein I also want to get callbacks from the object. Sort of
similar to other scripting languages such as VB, where events can be
updated. Any ideas how this is done.
------------------------------
Date: Wed, 20 Aug 1997 12:26:53 +1000
From: Geoffrey Dunn <gdunn@lis.net.au>
Subject: Re: Perl Win95
Message-Id: <33FA55ED.393B@lis.net.au>
mudd97@nac.net wrote:
>
> I am trying to test perl stuff on PWS on win95. I can't get anything
> going.
> Not even the "helloworld.pl" script. I set my scripts directory to
> execute and not read but it forbids read-access.
> I added .pl to my registry and the associations in win95. When I click
> on the .pl file a DOS windows comes up and executes the script and then
> disappears. Can anyone please help.
Heh, I remember this problem... lets see now how did I fix it...
Ah ha. I made a batch file that looks like so:
----
Perl.exe %1 > c:\tempfile\output.txt
Notepad.exe c:\tempfile\output.txt
----
And accociated that with the .pl files. It's kinda neat because output
goes to notepad and errors are in the DOS screen that does not vanish on
you...
Geoff
Ah ha!
P.S. Don't listen to the idiots who think your trying to run CGI.
Geoffrey Dunn gdunn@lis.net.au
http://spike.scu.edu.au/~gdunn10/
If you take my comments seriously, please
take two aspirins and see me in the morning.
Member of Australians United Against Gherkins.
------------------------------
Date: Wed, 20 Aug 1997 06:18:58 GMT
From: davey@harvard.edu (David Bauman)
Subject: Re: Q: Assignment by symbolic reference???
Message-Id: <33fa8b80.2632415@bigheera>
On Tue, 19 Aug 1997 21:26:48 GMT, davey@harvard.edu (David Bauman)
wrote:
Thanks to icd of Expert's Exchange for answering this one
for me... ( http://www.experts-exchange.com/topics/comp/lang/perl/ )
> $furry = '$dog, $cat, $bunny, $werewolf';
>
>What I want to be able to do is to then assign values
>(with a split() or somesuch) to $dog, $cat, etc.
>(Assuming that $food contains "steak:mice:carrots:people",
>I want to wind up with $dog eq "steak", $cat eq "mice", etc.)
>
> ($$furry) = split(":", $food) # this aint right...
>
> ( @$$furry ) = split(":", $food);
> # this gets the values into single scalar...
Try the 'eval' function. You would then have something like:
$food = "steak:mice:carrots:people";
$furry = '$dog, $cat, $bunny, $werewolf';
eval "($furry) = split(\":\", \$food)";
[ d*b ]
------------------------------
Date: 20 Aug 1997 11:15:41 +0200
From: Ronald Fischer <rovf@earthling.net>
Subject: Re: readig a file into an array
Message-Id: <xz2d8n9cj0i.fsf@uebemc.siemens.de>
>>>>> On Tue, 19 Aug 1997 15:36:59 -0400
>>>>> "EVB" == Ed Vander Bush <temp.ed.vanderbush@bentley.com> wrote:
EVB>
EVB> Can I
EVB> open a file
EVB> @my_array = filehandle
EVB> close file
EVB> Id there anything wrong with this?
Yes: you should use
@my_array = <filehandle>;
--
Ronald Fischer (rovf@Earthling.net) (PGP public key available)
http://ourworld.compuserve.com/homepages/ronald_fischer/
[When posting a followup, mailing a courtesy copy is fine, provided it is
clearly marked as such.]
------------------------------
Date: 20 Aug 1997 03:00:28 GMT
From: Eli the Bearded <usenet-tag@qz.little-neck.ny.us>
Subject: Re: regexp C library
Message-Id: <eli$9708192255@qz.little-neck.ny.us>
In article <5tcfs3$nkc@news.asu.edu>, <sieben@imap1.asu.edu> wrote:
> Is there a port of perl's regular expression library for C? I ve found some
> regular expression implementations but they seem too simple, especially
> for substitutions.
RTFM perlembed, HTH.
Elijah
------
libperl.so will save you a great deal of disk space, BTW
------------------------------
Date: Wed, 20 Aug 1997 17:43:21 +1000
From: bigiain@mightymedia.com.au (Iain Chalmers)
Subject: Re: Retrieving graphic dimensions through PERL w/o actually loading image?
Message-Id: <bigiain-ya02408000R2008971743210001@news.ozemail.com.au>
In article <33fa361d.4759481@news.mindspring.com>, (Raleigh) wrote:
> I am writing some Perl CGI scripts that manipulate images. My problem
> is that I want to include the WIDTH and HEIGHT attributes with the
> HTML code I send back to the client and the images I work with are of
> varying sizes.
>
> Any suggestions?
hi there,
here's a subroutine i wrote (way back whenever) that will extract the sizes
of gifs and jpegs (only rbg jpegs tho, not cmyk)
i use macperl (ie, this runs on a macintosh), so you'll need to change the path
separator from : to /. you'll also need to tidy it up if you want to use strict,
or the -w switch. i wrote this to run in perl 4, while i was learning...
there may be a much better way to do this, but this has worked for me for
about 2
years now - i don't use it in a speed critical task.
cheers
iain
#---------------------------------------------------------------------------
sub imagesize{
$temp="";
local($image)="";
local($widthlow,$widthhigh,$heightlow,$heighthigh,$width,$height);
local($tag)="";
$image=@_[0];
local($temp)=rindex($image,':');
if ($temp != -1){
$thisimage=substr($image,0,$temp).'2:'.substr($image,$temp+1,1).substr($imag
e,$temp,length($image)-$temp);
}
if (!-e $thisimage){print STDERR "$image - Missing\n";}
open (PIC, $thisimage) || die return(); ## this is bad! it should check
the return code...
read(PIC,$tag,10);
if (substr($tag,0,3) eq "GIF") {&gifsize();}
else {&jpegsize();}
sub jpegsize{
seek(PIC,617,0);
$heighthigh=ord(getc(PIC));
$heightlow=ord(getc(PIC));
$widthhigh=ord(getc(PIC));
$widthlow=ord(getc(PIC));
$width=256*$widthhigh+$widthlow;
$height=256*$heighthigh+$heightlow;
$result=" WIDTH=\"$width\" HEIGHT=\"$height\" ";}
## if ($width >= 500 || $height >= 400) ## this checks for my
maximum image sizes
## {print STDERR "Problem with $SInternetcode1 - WIDTH=$width
HEIGHT=$height\n";}
}
sub gifsize{
$widthlow=ord(substr($tag,6,1));
$widthhigh=ord(substr($tag,7,1));
$heightlow=ord(substr($tag,8,1));
$heighthigh=ord(substr($tag,9,1));
$width=256*$widthhigh+$widthlow;
$height=256*$heighthigh+$heightlow;
$result=" WIDTH=\"$width\" HEIGHT=\"$height\" ";
}
}
1; #return size in html format
#---------------------------------------------------------------------------
Iain Chalmers
bigiain@mightymedia.com.au
------------------------------
Date: 20 Aug 1997 07:05:16 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Round Function
Message-Id: <5te4vc$q8p$1@lyra.csx.cam.ac.uk>
Gary Chambers <geecee@netquarters.net> wrote:
>I now have the Round function that I need to better balance an
>amortization table in a CGI application I've written. Could I get some
>constructive criticism on what I've done? Here it is:
>
>use POSIX qw/floor ceil/;
>.
># Credit Fred Feuerbacher for the C-version of this function. He has
># released it to the public domain. All I did was Perl-ize it.
>sub Round #(long value, int precision)
>{
> local($pr = $_[1]);
> while ($pr > 0)
> {
> $_[0] *= 10;
> $pr--;
> }
Why use a loop for scaling here, when you use exponentiation below?
>
> $temp = ($_[0] >= 0.0 ? floor($_[0] + 0.5) : ceil($_[0] - 0.5));
> $_[0] = $temp / (10 ** $_[1]);
>
> $_[0];
>}
>
>It works as planned, but I'm not sure if I'm asking for trouble
>returning a modified parameter. I can, of course, create a temporary
>variable and return it, but it seemed the way I did it was easier. I'm
>lazy, you see...
You certainly are asking for trouble. Sooner or later that'll bite
someone. And it's not even the lazy of doing it. And (worst of all)
all that $_[0] stuff is just plain ugly.
And now that you've shown us what you _actually_ want to do, we can see
that "int" is suitable for the job. The difficulty with int is the
handling of negative numbers, but since you're treating positive and
negative separately, that doesn't apply.
So here's my version (untested):
sub Round {
my $v = shift;
my $scale = 10**shift;
$v *= $scale;
return ( $v >= 0 ? int($v+0.5) : -int(-$v+0.5) ) / $scale;
};
Mike Guy
------------------------------
Date: 20 Aug 1997 10:53:04 +0200
From: Ronald Fischer <rovf@earthling.net>
To: Russ Allbery <rra@stanford.edu>
Subject: Still not solved (was: Pattern repacement with variables question)
Message-Id: <xz2iux1ck27.fsf_-_@uebemc.siemens.de>
>>>>> On 18 Aug 1997 12:18:06 -0700
>>>>> "RA" == Russ Allbery <rra@stanford.edu> wrote:
RA> Vince Busam <vincent.busam@ngc.com> writes:
RA>
>> $test = "one two";
>> $match = '^([^ ]+) +([^ ]+)';
>> $replace = '$2 $1';
>> $test =~ s/$match/$replace/;
>> print "$test\n";
RA>
>> The output is:
>> $2 $1
RA>
>> instead I'd like to see:
>> two one
RA>
RA> Change the substitution line to:
RA>
RA> $test =~ s/$match/$replace/ee;
Did you ever try this? Changing the original code to
$test = "one two";
$match = '^([^ ]+) +([^ ]+)';
$replace = '$2 $1';
$test =~ s/$match/$replace/ee;
print "$test\n";
I get the error message
Scalar found where operator expected at (eval 1) line 1, near "$2 $1"
(Missing operator before $1?)
Using two 'e' don't make sense to be; the Camel book, at least, does
not mention any effect of doubling the /e modifier, so I tried the
variant
$test =~ s/$match/$replace/e;
This produced no error, but the result was identical to what Vince got
in the first place: $2 $1 instead of two one.
In this particular case, one could write
eval('$test =~ s/$match/'."$replace/);
but this is not feasible in general, since $replace might contain a slash.
--
Ronald Fischer (rovf@Earthling.net) (PGP public key available)
http://ourworld.compuserve.com/homepages/ronald_fischer/
[When posting a followup, mailing a courtesy copy is fine, provided it is
clearly marked as such.]
------------------------------
Date: Wed, 20 Aug 1997 09:24:08 BST
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: Unix pwd
Message-Id: <1997Aug20.092408@ukwit01>
|> On Mon, 18 Aug 1997, Michael Danielsson wrote:
|>
|> I would like to check if i am standing in the directory /tmp. How do I
|> do this in perl.
|>
The following works on Unix, and doesn't involve you chdir'ing
anywhere.
Use as:
amin 'directory'
and it will return 1 (true) if you are or 0 (false) if you are not.
sub amin {
my $check = shift;
my @a, @b;
@a = stat '.' or return 0;
@b = stat $check or return 0;
# Only check the "constant" fields (others could change between stat
# calls on the same object). These ae $dev, $ino, $rdev and $blksize.
foreach $i (0, 1, 6, 11) {
if ($a[$i] ne $b[$i]) {
return 0;
}
}
return 1;
};
--
----------- Gordon Lack ----------------- gml4410@ggr.co.uk ------------
The contents of this message *may* reflect my personal opinion. They are
*not* intended to reflect those of my employer, or anyone else.
------------------------------
Date: Wed, 20 Aug 1997 08:37:05 +0200
From: Marten Trautwein <martt@elsevier.nl>
Subject: Wanted: list of known bugs
Message-Id: <33FA9091.D9D8E572@elsevier.nl>
Hi,
Does anyone out there known where I can find a up-to-date list of known
bugs and undocumented features for Perl 5? Of course I went to the Perl
homepage and visited the Perl Bugs Index
http://perl-com.songline.com/bugs/
and the Recent Perl Bugs
http://perl-com.songline.com/bugs/Recent.html
Alas this (Recent) Perl Bugs Index has not been updated since early
1996. And whatismore, it did not address my problem. I have searched the
net for other bug-lists, but eventually they all appeared to refer to
the above mentioned pages.
I will gladly post a summary of the relevant responses: comments, URLs,
etc.
Thanks in advance.
Marten Trautwein,
m.trautwein@syllogic.nl,
Syllogic, BV
Houten, The Netherlands.
------------------------------
Date: 20 Aug 1997 06:56:32 GMT
From: trockij@transmeta.com (Jim Trocki)
Subject: Re: writing to a file
Message-Id: <5te4f0$enc$1@palladium.transmeta.com>
In article <33F951E6.5828@hem.passagen.se>,
Robban <colte@hem.passagen.se> wrote:
>Hello I'm a Perl beginner running perl 5.
An excellent language to learn.
>When I write to a file using the append mode
>it places it at the end of the file.
>I want to replace a line in the middle of the file.
>(For updating a html page)
>Does anyone know how to accomplish this ?
rename ("file.html", "old.html");
open (IN, "old.html") || die;
open (OUT, ">file.html") || die;
while (<IN>) {
if (/^the line you want to match$/) {
print OUT "the line you want to replace this with\n";
next;
}
print OUT;
}
close (IN);
close (OUT);
unlink ("old.html");
Jim Trocki
Computer System and Network Engineer
Transmeta Corporation
Santa Clara, CA trockij@transmeta.com
--
Jim Trocki
Computer System and Network Engineer
Transmeta Corporation
Santa Clara, CA trockij@transmeta.com
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 893
*************************************