[6995] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 620 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 16 22:07:18 1997

Date: Mon, 16 Jun 97 19:00:24 -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           Mon, 16 Jun 1997     Volume: 8 Number: 620

Today's topics:
     Re: Checking existence of file in other people's direct <rra@stanford.edu>
     Copy with PERL ? (Lopez)
     Debugging tutorial? (Michael Schuerig)
     Re: different integers output by print and printf? (Bob Apthorpe)
     Re: GD and HTML together (Jason Costomiris)
     Re: Get own IP - Part II (Charles DeRykus)
     Re: Help building a regexp (bug?) (Bob Apthorpe)
     Help w/ Data Structures (Eric Finley)
     Re: Help w/ Data Structures (Eric Finley)
     Re: HELP: How to limit the length of contents in guestb (Craig Berry)
     Re: horrible idea (Charles DeRykus)
     Re: How do you direct STDERR into a pipe? (Tad McClellan)
     Re: justa question... (Jason Costomiris)
     Re: LOG base 10  operator <mcontois@sig.bsh.com>
     Re: Look for a good IDE for win32 (Jason Costomiris)
     Re: map feature request (Charles DeRykus)
     Need help with regexp in substitution (Mark R. Tobias)
     Re: not printing (Tad McClellan)
     PERL Amiga..... (Geoff Taylor)
     Re: perl and refs <rra@stanford.edu>
     Re: perl and refs (Charles DeRykus)
     Re: Printing Prime Numbers (Abigail)
     Q: multi-dimensional Associative Arrays ... how ??? (Greg Sylvain)
     Re: Q: multi-dimensional Associative Arrays ... how ??? (Jot Powers)
     unpack, record length. (Darwin O.V. Alonso)
     What is CGI? <esupu@warwick.ac.uk>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 16 Jun 1997 16:56:05 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Checking existence of file in other people's directories...
Message-Id: <m3soyiksq2.fsf@windlord.Stanford.EDU>

Keys <keys@babylon5fan.com> writes:

> I've written a simple Perl script that prints a list of a system's users
> and links to their homepages, iff (if and only if) they exist.  The
> problem is, when I run it from the webserver as a CGI, it works fine,
> since the webserver has access to all web dirs, but when I execute it
> under my uid (from my login shell or as a crontab), I don;t have the
> permissions to go sniffing for index.html in others' webdirs...

Well, Perl isn't going to let you bypass a permissions problem.  If you
don't have the permissions required to get a list of index.html files,
then you don't have the permissions required.  If that's what you need to
do, your script to do so is going to have to run from a user account that
has the required permissions.

> The webdirs are actually in the form /home/httpd/html/username/ but they
> are also aliased as ~username/public_html/.  Does anyone have any other
> ideas how I might check for the indices?  The directories exist for all
> users (but not index.html), so I can't look for that (besides, I don't
> have read permission in /home/httpd/html/ so I can't get a list anyway),
> and most of the webdirs have permission 700 or 600...

This is an absolutely bizarre set of permissions for web directories; web
directories are nearly uniformly world-readable on regular Unix systems
since the web server runs with no special permissions.  Is this ISP
running a web server with special permissions so that it can get access to
these directories?  If so, I think this web site has some fairly severe
security problems, particularly if the web server is running as root.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Thu, 12 Jun 1997 12:41:11 GMT
From: jlsantos@mail.telepac.pt (Lopez)
Subject: Copy with PERL ?
Message-Id: <339fedea.9406912@news.telepac.pt>

Can any one tell me if it is possibel to
have a routine that makes a copy of
somes files in one directory to
other directory ?

ex.:  /www2/mysite/user1

copy to

/www2/mysite/user2

????????

is this possibel ?  how can i do it ?

Thanks
Joaquim



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

Date: Tue, 17 Jun 1997 00:48:55 +0200
From: uzs90z@uni-bonn.de (Michael Schuerig)
Subject: Debugging tutorial?
Message-Id: <199706170048551642226@rhrz-ts2-p4.rhrz.uni-bonn.de>


When debugging my scripts I usually resort to using print statements.
Now, this has to change. Can anyone point me to a tutorial on using the
debugger? The offerings of _Programming in Perl_ and perldebug are a bit
too terse for me.

Michael

---
Michael Schuerig           Contests between male toads over females are
mailto:uzs90z@uni-bonn.de      often settled by the depth of the croak.
http://www.uni-bonn.de/~uzs90z/                     -John Maynard Smith


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

Date: Tue, 17 Jun 97 00:12:16 GMT
From: arclight@io.com (Bob Apthorpe)
Subject: Re: different integers output by print and printf?
Message-Id: <5o4kpd$fsg@news.jump.net>

In article <mu267vgea00.fsf@c00127-100lez.eos.ncsu.edu>,
   Tom Roche <tlroche@eos.ncsu.edu> wrote:
>
>I'm using Perl to do a little combinatoric homework. I ran (with
>Perl 5.003 on Solaris 2.4 on a Sparcstation 4) the following code:

You might also get the Math::BigInteger module from CPAN if installing new 
modules is an option for you.

Bob Apthorpe (still wondering where his combinatorics book wandered off to...)
arclight at jump dot net


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

Date: 16 Jun 1997 22:02:22 GMT
From: jcostom@shaft.sjis.com (Jason Costomiris)
Subject: Re: GD and HTML together
Message-Id: <slrn5qbdt9.elc.jcostom@dogbert.sjis.com>

On Sat, 14 Jun 1997 22:01:33 -0600, cwt1959@rit.edu <cwt1959@rit.edu> wrote:
: push (@INC, "cgi-bin");
: require("cgi-lib.pl");

Stop that! LART LART LART...  Use CGI.pm.  You've already started down
the correct path by using GD.pm, don't go over to the dark side and use
cgi-lib.pl.  Don't get me wrong, cgi-lib.pl was great when all we had was
perl 4, but these days, CGI.pm has got it all over cgi-lib.pl.

You'll find it a whole lot more workable to do something like:

#!/usr/bin/perl

use CGI;
use GD;

srand;
$random = int(rand(999999));

$image = new GD::Image(45,25);
$white = $image->colorAllocate(255,255,255);
$black = $image->colorAllocate(0,0,0);
$image->interlaced('true');
$image->fill(0,0,$black);
$image->string(gdMediumBoldFont,2,5,$random,$white);

$cgi = new CGI;
print $cgi->header('image/gif');
print $image->gif;

This nifty little wonder simulates one of those tacky web page counters,
only this one randomly chooses a number of hits between 0 and 999999.

Then you call it from your HTML as:

<img src="/cgi-bin/foo.cgi">

-- 
Jason Costomiris                 | Finger for PGP 2.6.2 Public Key
jcostom@sjis.com                 | "There is a fine line between idiocy
My employers like me, but not	 | and genius.  We aim to erase that line"
enough to let me speak for them. |			--Unknown

	        	http://www.jasons.org/~jcostom


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

Date: Mon, 16 Jun 1997 21:53:43 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Get own IP - Part II
Message-Id: <EBw25K.L39@bcstec.ca.boeing.com>

In article <33A02308.79A1@informatik.tu-muenchen.de>,
Alex `Taker` Pircher  <pircher@informatik.tu-muenchen.de> wrote:
>
>    use Socket;
>    use Sys::Hostname;
>    my $host = hostname();
>    my $addr = inet_ntoa(scalar(gethostbyname($name)) || 'localhost');
>
>But the result is: Cannot get host name of local machine at ./xx line x
>
>What's wrong?
>
    my $addr = inet_ntoa(scalar(gethostbyname($name)) || 'localhost');
                                              ^^^^^
                                              $host

--
Charles DeRykus
ced@carios2.ca.boeing.com


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

Date: Tue, 17 Jun 97 01:08:50 GMT
From: arclight@io.com (Bob Apthorpe)
Subject: Re: Help building a regexp (bug?)
Message-Id: <5o4o3g$fsg@news.jump.net>

In article <EBA1M6.3qI@mv.mv.com>, sdn@mv.mv.com (Eric Roode) wrote:
>In article <Pine.GSO.3.96.970604154807.26571F-100000@kelly.teleport.com>,
>Tom Phoenix  <rootbeer@teleport.com> wrote:
>>The solution is to use quotemeta on the items before they're ready for
>>interpolation, something like this. (I haven't checked this, but I think
>>it will do what you need.)
>>
>>    @names = qw(fred barney mr.slate dino);
>>    $any = join "|", map(quotemeta($_), @names);
>>    $pattern = "$any.*?$any";
>>
>>Hope this helps!
>
>Excellent! I'm sure it will. Thanks.

Two quick questions: Is your data such that you might run into

(---junk---) fred (---junk---) fred (---junk---) fred  (---junk---) 

Remember, ".*" is greedy so 

             |<-----    Matches               ----->|      
(---junk---) fred (---junk---) fred (---junk---) fred  (---junk---)
             |<---- Not This ---->|

Second, do you want the bracketing words to match as in
fred (---junk---) fred
or is
fred (---junk---) barney
OK?

See what happens when you start reading "Mastering Regular Expressions" (ORA, 
Jeffery Friedl) - you become even _more_ paranoid...

Bob


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

Date: 16 Jun 1997 22:36:59 GMT
From: ez041407@dilbert.ucdavis.edu (Eric Finley)
Subject: Help w/ Data Structures
Message-Id: <5o4f6b$hn0$1@mark.ucdavis.edu>

Hi, 
I have the following data structure:
$timing = {
    INPUT => {
        INPUT => [
            INPUT => {
                NAME            => { %name_info },
                SRISING         => [ @setup_rising ],
                SFALLING        => [ @setup_falling ],
                SEDGE           => $sedge,
                SREF_CLK        => $sref_clk,
                SMULTIM         => $smultim,
                HRISING         => [ @hold_rising ],
                HFALLING        => [ @hold_falling ],
                HEDGE           => $hedge,
                HREF_CLK        => $href_clk,
                HMULTIM         => $hmultim,
            },
        ],
        NUM_INPUTS => $num_inputs,
        DIR             => $direction,
    },

    OUTPUT => {
        OUTPUT => [
            OUTPUT => {
                NAME => [
                    NAME => {
                        NAME    => $hold_name,
                        REF_CLK => $hold_ref_clk,
                        REF_EDGE => $reledge,
                        CAP     => $hold_cap,
                    },
                ],
                F_DELAY => [ @f_delay ],
                F_TRANS => [ @f_trans],
                R_DELAY => [ @r_delay ],
                R_TRANS => [ R_DELAY ],
            },
        ],
        NUM_OUTPUTS => $num_outputs,
        DIR     => $out_dir,
    },

    CLK => {
        CLK2 => [
            CLK3 => {
                NAME    => $clk_name,
                CAP     => $capacitance,
                MPW_HIGH => $mpwh,
                MPW_LOW  => $mpwl,
                CLOCK    => $clock,
            },
        ],
        NUM_CLK => $num_clk,
    },
};

this structure has evolved from 3 simpler structures.  When I try doing:
        while (<INFILE>) {
            last if (/^\s*?\n$/);
            $timing->{CLK}->{NUM_CLK}++;
            ($timing->{CLK}[ $timing->{CLK}->{NUM_CLK} ]->{NAME},
            $timing->{CLK}[ $timing->{CLK}->{NUM_CLK} ]->{CAP},
            $timing->{CLK}[ $timing->{CLK}->{NUM_CLK} ]->{MPW_HIGH},
            $timing->{CLK}[ $timing->{CLK}->{NUM_CLK} ]->{MPW_LOW},
            $timing->{CLK}[ $timing->{CLK}->{NUM_CLK} ]->{CLOCK}) 
		= split /\s+/;
        }
I get the following error:
Not an ARRAY reference at convert.pl line 133, <INFILE> chunk 8.
Now the code I wrote in the previous verion worked but I can't seem to
make this work.  Other lines that are similar seem to work.  Any help
would be very appreciated.
Thanks,
Eric Finley



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

Date: 16 Jun 1997 23:07:35 GMT
From: ez041407@dilbert.ucdavis.edu (Eric Finley)
Subject: Re: Help w/ Data Structures
Message-Id: <5o4gvn$iml$1@mark.ucdavis.edu>

Eric Finley (ez041407@dilbert.ucdavis.edu) wrote:
: Hi, 
: I have the following data structure:
: $timing = {
:     INPUT => {
:         INPUT => [
:             INPUT => {
:                 NAME            => { %name_info },
:                 SRISING         => [ @setup_rising ],
:                 SFALLING        => [ @setup_falling ],
:                 SEDGE           => $sedge,
:                 SREF_CLK        => $sref_clk,
:                 SMULTIM         => $smultim,
:                 HRISING         => [ @hold_rising ],
:                 HFALLING        => [ @hold_falling ],
:                 HEDGE           => $hedge,
:                 HREF_CLK        => $href_clk,
:                 HMULTIM         => $hmultim,
:             },
:         ],
:         NUM_INPUTS => $num_inputs,
:         DIR             => $direction,
:     },
: 
:     OUTPUT => {
:         OUTPUT => [
:             OUTPUT => {
:                 NAME => [
:                     NAME => {
:                         NAME    => $hold_name,
:                         REF_CLK => $hold_ref_clk,
:                         REF_EDGE => $reledge,
:                         CAP     => $hold_cap,
:                     },
:                 ],
:                 F_DELAY => [ @f_delay ],
:                 F_TRANS => [ @f_trans],
:                 R_DELAY => [ @r_delay ],
:                 R_TRANS => [ R_DELAY ],
:             },
:         ],
:         NUM_OUTPUTS => $num_outputs,
:         DIR     => $out_dir,
:     },
: 
:     CLK => {
:         CLK2 => [
:             CLK3 => {
:                 NAME    => $clk_name,
:                 CAP     => $capacitance,
:                 MPW_HIGH => $mpwh,
:                 MPW_LOW  => $mpwl,
:                 CLOCK    => $clock,
:             },
:         ],
:         NUM_CLK => $num_clk,
:     },
: };
: 
: this structure has evolved from 3 simpler structures.  When I try doing:
:         while (<INFILE>) {
:             last if (/^\s*?\n$/);
:             $timing->{CLK}->{NUM_CLK}++;
:line:133     ($timing->{CLK}[ $timing->{CLK}->{NUM_CLK}]->{NAME},
:             $timing->{CLK}[ $timing->{CLK}->{NUM_CLK} ]->{CAP},
:             $timing->{CLK}[ $timing->{CLK}->{NUM_CLK} ]->{MPW_HIGH},
:             $timing->{CLK}[ $timing->{CLK}->{NUM_CLK} ]->{MPW_LOW},
:             $timing->{CLK}[ $timing->{CLK}->{NUM_CLK} ]->{CLOCK}) 
: 		= split /\s+/;
:         }
: I get the following error:
: Not an ARRAY reference at convert.pl line 133, <INFILE> chunk 8.
: Now the code I wrote in the previous verion worked but I can't seem to
: make this work.  Other lines that are similar seem to work.  Any help
: would be very appreciated.
: Thanks,
: Eric Finley
: 
Sorry I forgot to indicate the line number.
Eric



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

Date: 16 Jun 1997 23:50:09 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: HELP: How to limit the length of contents in guestbook script?
Message-Id: <5o4jfh$jaj$1@marina.cinenet.net>

Jimmy (jhsetyo@students.wisc.edu) wrote:
: Hi, I have a guestbook script that was created using perl 5, and I want
: to limit the length of user's comments. Let say 500 characters. 
: 
: So, if someone write his comment over 500 characters, he will
: get a message to warn him.
: 
: How can I do that?

Let's presume you have the user's comments in a variable named 
$comments.  The following fragment will chop to 500 chars, add an 
ellipsis of your choosing, and warn the user if the comment length 
exceeds 500:

  # Warning - not tested, typing directly to news post...

  $comments_length_limit = 500;

  if (length($comments) > $comments_length_limit) {
    my $ellipsis = ' [...]';

    substr($comments, $comments_length_limit) = $ellipsis;

    print "Warning: Comments too long - truncated at $comments_length_limit characters.\n";
  }

Note that if you're using this in a CGI script (as seems likely), you'll 
probably want to wrap some HTML tags around that warning message to (for 
example) put it in a separate paragraph, perhaps bolded or in a larger 
size or whatever, to make it stand out better.

Hope this helps!

PS for the anal-retentive: The code above actually ends up limitting the
stored comment size to ($comments_length_limit + length($ellipsis)
characters.  Resolution of this is left as an exercise for the student. :)

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


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

Date: Mon, 16 Jun 1997 23:19:43 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: horrible idea
Message-Id: <EBw64v.3J2@bcstec.ca.boeing.com>

In article <339CC13D.2351@bender.com>,
Rubbish  <alex.t.silverstein@bender.com> wrote:
 > I want to quantify the exact number of
 > times a substitution is performed;
 > I am also curious if the number of times
 > a function like 'eval' can be easily set.
 > Ok, so maybe it's not a horrible idea,
 > but I am learning perl on my own, so
 > it seems so.


Perhaps something like this which would eliminate the eval 
altogether:


$_ = "java java java java java ..."; 
s/java/perl/ until $count++ == 3;   # leaves a trailing java :) 


HTH,
--
Charles DeRykus
ced@carios2.ca.boeing.com


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

Date: Mon, 16 Jun 1997 19:54:20 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: How do you direct STDERR into a pipe?
Message-Id: <s7n4o5.io5.ln@localhost>

Jim O'connor (joconnor@fwhre13.fwrdc.rtsg.mot.com) wrote:
: Let's say I have a fragment like this in a PERL script:

OK.

You have a fragment like this in a PERL script ;-)


:  $ducmd   = "du | sort -n -r";
:  open( DU, "$ducmd |") || die "Can't run $ducmd";
                                 ^^^^^^^^^^^^^^^^

That is a pretty misleading error message.

If the die() ever does get executed, it will be *before* $ducmd
ever got a chance to even try and execute...


See this question in the Perl FAQ:

"Why doesn't open() return an error when a pipe open fails?"



: When I run this, du writes error messages ("cannot open ...",
: "bad status", etc) to stderr, which clutter up the output. I'd
: like to redirect stderr to my PERL code, and handle the errors
: in there.

: How does one get PERL to redirect (not copy) stderr so it's 
: available to the PERL script?


See this question in the Perl FAQ:

"How can I capture STDERR from an external command?"

<rant>
Does that sound like your question? It sounds like a question that all
the regulars here have seen with such frequency that they got tired of
answering the Damn thing yet again, so they wrote it up once and for
all and put it into the Perl FAQ.

So that the clueless could just go ahead and ignore it...
</rant>



You are expected to spend some miniscule effort of your own by 
checking the FAQ before you post and ask others to spend effort
on your behalf.


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


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

Date: 17 Jun 1997 00:28:46 GMT
From: jcostom@shaft.sjis.com (Jason Costomiris)
Subject: Re: justa question...
Message-Id: <slrn5qbmfr.evm.jcostom@dogbert.sjis.com>

On Mon, 16 Jun 1997 13:46:03 GMT, NightHawk <heron@web-access.net> wrote:
: 
: Will this bit of code utilize "GET" Methods?

No.  Please pick a better subject next time.  It looks like you don't
understand the difference between GET and POST either.

: It looks like it could but, when I changed the 
: Method on the HTML form to "GET."  It didn't work.

Read about GET and POST, it will suddenly become obvious why your code
doesn't work.

: And if this ISN'T the beginning of a "GET" Perl
: program, I would appreciate it if you would show me
: where one might be.

#!/usr/bin/perl

use CGI;
$query = new CGI;

There, that's the beginning.  It will work, GET or POST.


-- 
Jason Costomiris                 | Finger for PGP 2.6.2 Public Key
jcostom@sjis.com                 | "There is a fine line between idiocy
My employers like me, but not	 | and genius.  We aim to erase that line"
enough to let me speak for them. |			--Unknown

	        	http://www.jasons.org/~jcostom


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

Date: Mon, 16 Jun 1997 20:34:48 -0400
From: Mark Contois <mcontois@sig.bsh.com>
Subject: Re: LOG base 10  operator
Message-Id: <33A5DBA8.167E@sig.bsh.com>

Michael J. Rocchetti wrote:

> Does anyone know how to take the log base 10 of a number using PERL?

    log($number)/log(10)

Works every time.

-- 
Mark Contois                 | Actual Windows NT error message:
Strategic Interactive Group  |       "No keyboard found.
Boston, MA                   |        Press F1 to continue."


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

Date: 17 Jun 1997 00:32:01 GMT
From: jcostom@shaft.sjis.com (Jason Costomiris)
Subject: Re: Look for a good IDE for win32
Message-Id: <slrn5qbmlu.evm.jcostom@dogbert.sjis.com>

On Sun, 15 Jun 1997 03:02:00 -0500, Joshua Frank <joshua@midwest.net> wrote:
: Does anyone know of a good integrated development enviroment for windows
: 95.
: I getting tired of writing my programs with notepad. I found a one for perl
: 4 but I could find one for perl 5. 

I found this fantastic cross-platform script editing environment that I can
use on *nix variants, NT, Lose95, my PowerBook, even VMS...

http://www.math.fu-berlin.de/~guckes/vim/

:-)

-- 
Jason Costomiris                 | Finger for PGP 2.6.2 Public Key
jcostom@sjis.com                 | "There is a fine line between idiocy
My employers like me, but not	 | and genius.  We aim to erase that line"
enough to let me speak for them. |			--Unknown

	        	http://www.jasons.org/~jcostom


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

Date: Mon, 16 Jun 1997 22:59:08 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: map feature request
Message-Id: <EBw56L.2IA@bcstec.ca.boeing.com>

In article <5ntcvb$l79$1@news13.gte.net>,
Douglas Wilson  <dgwilson@gte.net> wrote:
 > While I was discovering that the following
 > would parse my string into the desired
 > associative array:
 > 
 > $qstring="a=one&b=two&c=three";
 > 
 > %myarr=map {split(/=/,$_)} split(/&/,$qstring);
 > 
 > I wondered if the following would work also:
 > 
 > (@names, @values) = map {split(/=/,$_)} split(/&/,$qstring);
 > 
 > but the second statement didn't work. It would be a great
 > feature if it did though.
 > 

  Alternatively, you could trade in "split,map" for "push,regex":

  push(@names,$1),push(@values,$2) while $qstring =~ /(.*?)=(.*?)&/g; 


HTH,

--
Charles DeRykus
ced@carios2.ca.boeing.com


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

Date: 16 Jun 97 23:24:17 GMT
From: mtobias@liberty.uc.wlu.edu (Mark R. Tobias)
Subject: Need help with regexp in substitution
Message-Id: <33a5cb21.0@logic.uc.wlu.edu>

I am working on a perl script that will help me convert some html 
documents.  Basically, I am looking to do two things.  The first is to 
remove all IMG SRC tags.  The second is to remove all external HREF 
tags.  

Now, as far as the IMG SRC tags, this is what I did:

   open(FILE,"$file");
   @lines = <FILE>;
   close(FILE);

   open(FILE,">$file") || die "Can't Open $file\n";
   foreach $line(@lines) {
      $line =~ s/<IMG(.*)>//gi;
      print FILE "$line";
   }
   close(FILE); 

This works to remove the IMG SRC tag, but there is a problem.  It also 
removes everything past the IMG SRC tag.  For instance if the <IMG> is 
wrapped in a link tag, it removes the IMG src tag, and then it removes 
the </A> and it will also remove anything after that till the end of the 
line.  What I need to do is to remove <IMG SRC> tags from anywhere 
within the document, even mid-sentence.  If the IMG tag is wrapped in an 
<A HREF> tag, then I need to take the text out of the ALT tag and replace 
the IMG SRC tag with that text.  Basically, I am looking for the regexp 
that will substitute for strings that start with <IMG and then go until 
it sees the first >.  That will be good to remove all IMG SRC tags.  Once 
I get that done it shouldn't be too difficult to check the IMG SRC tag if 
it preceded by an HREF tag and if so, capture the ALT text and then 
replace the <IMG SRC> with that captured text, but again, I'm not sure 
how to go about it.


Well, that is for the IMG tags, for the HREF tags, I need to remove all 
external ones.  So, I assume I need to look in the HREF tag to see if it 
has a # to indicate it is a link to an anchor.  However, I'm not sure how 
to do this.


I know this has gone on as a long message but I have been working on it 
for hours and am very frustrated.  If you can help me ASAP (I need to 
have this done tomorrow) I would appreciate it.  Thank you very much.



Mark



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

Date: Mon, 16 Jun 1997 19:05:28 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: not printing
Message-Id: <8ck4o5.2k5.ln@localhost>

Eike Grote (eike.grote@theo.phy.uni-bayreuth.de) wrote:
: Hi,

: rroberts@gowebway.com wrote:
: > 
: > I meant line 5.  I changed it before I sent it.
: > Could someone tell me if this is my fault or perl's and why?
: > 
: > >This program is not printing at line 6. In all other ways it is
: > >working just fine.
: > >
: > >########################----  begin code
: > >#!/usr/bin/perl -w
: > >print "Give me a list of words and press^z when done.\n";
:                                       ^^^^^^^
: Do you really mean "press Ctrl-Z" ? On my machine/system this
: means "stop the process" (message: "Suspended"). If I enter
: Ctrl-D on an empty line everything works fine.


Ctrl-Z on Bill's stuff is roughly equivalent to Ctrl-D on a
real operating system.


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


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

Date: 15 Jun 97 01:19:26
From: dreamland@207.69.188.186 (Geoff Taylor)
Subject: PERL Amiga.....
Message-Id: <866359166mnewsdreamland@207.69.188.186>

Anyone out there using PERL on AMIGA?

or know if there is a PERL 5 compiler for WIN95/3.1/MSDOS

thanks

dreamland@mindspring.com





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

Date: 16 Jun 1997 16:52:49 -0700
From: Russ Allbery <rra@stanford.edu>
To: Patrick.Husi@de.epfl.ch
Subject: Re: perl and refs
Message-Id: <m3wwnuksvi.fsf@windlord.Stanford.EDU>

[ Posted and mailed. ]

Patrick Husi <Patrick.Husi@de.epfl.ch> writes:

> my %myhash;
> .
> .
> displayHash (\%myhash); #line 61

Your prototype is incorrect.  What you wanted was:

        sub displayHash (\%);

(The "sub" is required, and you don't want to give the name of the
variable -- there is no defined syntax for that..)

> sub displayHash {

You have to repeat the prototype from the forward declaration at the
actual sub definition, so this should be:

        sub displayHash (\%) {

That should fix the problems.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Mon, 16 Jun 1997 23:44:12 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: perl and refs
Message-Id: <EBw79p.5GE@bcstec.ca.boeing.com>

In article <33A556AE.39EF@de.epfl.ch>,
Patrick Husi  <Patrick.Husi@de.epfl.ch> wrote:
>in a perl script I call a sub with a ref:
>
>my %myhash;
>.
>.
>displayHash (\%myhash); #line 61
>
>sub displayHash {
>    my $input = @_;
>    print $input->{'keyXY'}; #line 135
>}
>
>
>On my computer there's no trouble, but at an another computer there are
>2 errors:
>
>"displayHash" may clash with future reserved word at test.pl line 61.
>parse error in file test.pl at line 61, next 2 tikens "displayHash("
>Spurious backslash ignored at test.pl line 61. 
>
>parse error in file test.pl at line 135, next 2 tokens "->"
>
>
>Both perl versions are 5.003. Does anyone know why it works only at one
>machine?

my $input = @_;
^^^^^^^^^^^^^^^   


Was this just a typo?  Should be 

my($input) = @_;   # or: my $input = $_[0];

Otherwise, you're evaluating @_ in a scalar context.


HTH,
--
Charles DeRykus
ced@carios2.ca.boeing.com


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

Date: Tue, 17 Jun 1997 01:17:34 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Printing Prime Numbers
Message-Id: <EBwBLA.59L@nonexistent.com>

Jay Flaherty (fty@hickory.engr.utk.edu) wrote on 1385 September 1993 in
<URL: news:5o45jb$8ml$2@gaia.ns.utk.edu>:
++ 
++ I tried the above and have the following result:
++ Global symbol "product" requires explicit package name at ./prime line 8.
++ Variable "$product" is not imported at ./prime line 8.
++ Global symbol "product" requires explicit package name at ./prime line 8.
++ "/pear/fty/.article" 53 lines, 1872 charactersn errors.
++
++ I remarked the "use strict" line and have the following result:
++ Use of uninitialized value at ./prime line 8.
++ 3$5$7$9$11$13$15$17$19$21$23$25$27$29$31$33$35$37$39$41$43$45$47$49$
++ 
++ I print all odd numbers starting at 3. Am I missing something?

$ perl -w
use strict;
my ($prime, $max) = (2, shift || 50);          # First prime, max number.
my @sieve = (0, 0, map {1;} ($prime .. $max)); # Init sieve.
while ((my $product = $prime * $prime) <= $max) {
    do {$sieve [$product] = 0;} while (($product += $prime) <= $max);
    do {$prime ++;}             while !$sieve [$prime];
}
map {print "$_," if $sieve [$_];} (0 .. $max);
print "\n";
__END__
2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,
$ uname -a
SunOS canopus 5.5.1 Generic_103640-03 sun4u sparc SUNW,Ultra-1
$ perl -v
 
This is perl, version 5.004
 
Copyright 1987-1997, Larry Wall
 
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
$

Perhaps you are running an old version of Perl?

++ BTW...I ran this on a Sun Ultra1. I also ran Randal's code and it screams.
++ Way faster than anyone so far.

[perl mode off, algorithm complexity mode on]
Randal's code is O (n^2/log n), while the sieve is O (n log n).
In fact, a commodore 64 using a sieve (and a cassette recorder as
extra memory) will beat the fastest Cray in more cases than it'll
lose.



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=new Math::BigInt+qq;$^F$^W783$[$%9889$^F47$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W98$^F76777$=56;;$^U=$]*(q.25..($^W=@^V))=>do{print+chr$^V%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: 16 Jun 1997 20:31:56 GMT
From: sylvain@nasirc.hq.nasa.gov (Greg Sylvain)
Subject: Q: multi-dimensional Associative Arrays ... how ???
Message-Id: <5o47rs$jmg@client2.news.psi.net>
Keywords: perlref, perlobj

	Hello all,

	I have a fairly basic question I hope someone can answer.

	I'm using Perl 5.003+ and I'm try to get a multiple associative
array implemented and I'm not having much luck.

	The semantics seem reasonable, but I cann't get the syntax of the
expression correct. I would like something like the following :

	%aArray() = {};

	$aArray{$host}{$user}++; # increment the number of times $user logged
			         # into $host
	$aArray{$host}{$user};   # what is the current loggin count for $user
				 # on $host
	.
	.
	.

	$aArray{$domain}{$host}{$user}++; #same for the domains

	.
	.
	.

	for $host (keys $aArray) {
          print "Users from $host\n";
	  for $user (keys $aArray{$host}) {

          }
	}

	Specifically, I'm trying to get a 3 dimensional associative array.

	Thanks in advance for any assitance or work-arounds,
	greg

-- 
--
Greg Sylvain                  Phone: 301.918.1985
sylvaing@lan.alliedtech.com   Fax:   301.918.8154


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

Date: 16 Jun 1997 23:30:59 GMT
From: jot@tmp.medtronic.com (Jot Powers)
Subject: Re: Q: multi-dimensional Associative Arrays ... how ???
Message-Id: <5o4ibj$7q2$1@gazette.corp.medtronic.com>

In article <5o47rs$jmg@client2.news.psi.net>, sylvain@nasirc.hq.nasa.gov (Greg Sylvain) writes:
>
>	for $host (keys $aArray) {
>          print "Users from $host\n";
>	  for $user (keys $aArray{$host}) {
>
>          }
>	}
>

Close.

foreach $host (keys %aArray) {
		print "Users from $host\n";
	for $user (keys %{ $aArray{$host}) {
		print "$user = $aArray{$host}{$user}\n";
	}
}

>	Specifically, I'm trying to get a 3 dimensional associative array.

The above (minus any typos ;) was shamelessly cobbled from:

http://www.perl.com/perl/everything_to_know/pdsc/pdsc-4.html

This is an invaluable resource for finding answers.

-- 
Jot Powers  jot@tmp.medtronic.com
Unix System Administrator, Medtronic Micro-Rel
"Subtlety is the art of saying what you think and getting out of the way
before it is understood."




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

Date: 17 Jun 1997 01:21:45 GMT
From: dalonso@u.washington.edu (Darwin O.V. Alonso)
Subject: unpack, record length.
Message-Id: <5o4or9$17l6@nntp6.u.washington.edu>



A perl script reading a long binary record aborts before
the end of the record with the warning:
x outside of string at ./readb line 18, <> line 1.
The length given by length($record)
is only 11202, but the length of the record should be
13368 (calculated).  

I suspect that the record/binary file is not at fault because
I can read the entire record/file using a program compiled from fortran src,
and in that case it reads past where the perl script bombs (*src shown below*).
The the fortran and perl reads match up to the point that the perl one bombs.


I know this is an imposition and a long shot, but:
any suggestions for handling this unholy alliance between fortran and perl?
I give the script, fortran src, and outputs below.
Also, I would very much appreciate suggestions on my use of unpack.

Thank you,
Darwin



#----------Start Perl Scrip stops at $i=161------------
#!/usr/local/bin/perl -w
$,=" "; $record = <>;

@nseq = unpack("i2", $record ); $ns=$nseq[1];	#get first some integer=$ns
$nska = 8 + $ns*12 + 4;				# calculate some byte skip = $nska
@sefo = unpack("x$nska i", $record );		#get some other integer=$nat
$nat = $sefo[0];
$nsk = 8 + $ns*12 + 8 + $nat*4 + $nat*4;	# calculate another  skip = $nsk

$length = length($record);
print "length\tns\tnat\tnsk (calc length 13368)\n";
print "$length\t$ns\t$nat\t$nsk\n";

# fortran int*2 now loop through 
for $i ( 0 .. $nat-1){
    @problem = unpack("x$nsk s", $record);  $nsk = $nsk+2;
    print $i, $t[0],"\n";
} 
#----------End Perl Scrip stops at $i=161------------


#----------Fortran exe correctly reads through $i=1244---------------
      integer*2 problem
      integer ns, nat
c     ***d[1-5] = various length dummy variables****
      read(unit) ns,(d1(i),d2(i),d3(i),i=1, ns),
     &d4(ns+1),nat,(d5(i),i=1,nat),
     &(d6(i),i=1,nat),(problem(i),i=1,nat)
c
      do i=1,nat
        write(6,'(i,x,2a4,2i)') i-1, problem(i)
      enddo



------------------- Example Outs -----------------------
perl out		       fortran out
index  value			index value
0	1 			  0    1
1	1			  1    1
2	1 			  2    1
 ...          *156 lines cut*
159	9 			  159  9
160	10 			  160 10
161  			          161 10
     			          162 10
*that's all*		        *continues*


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

Date: Tue, 17 Jun 1997 01:20:20 +0100
From: Mr Mah Hang Chin <esupu@warwick.ac.uk>
Subject: What is CGI?
Message-Id: <Pine.SOL.3.95.970617011749.28350A-100000@holly>

	I am a novice. Can anyone tell me what is CGI pls and what is so
good about it?
	Cheers.

Yours sincerely,
HANG CHIN



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

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

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