[11228] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4829 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 4 20:11:39 1999

Date: Thu, 4 Feb 99 17:01:34 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 4 Feb 1999     Volume: 8 Number: 4829

Today's topics:
    Re: Readdir gives me garbage... (I R A Aggie)
    Re: Readdir gives me garbage... (Martien Verbruggen)
    Re: Seek to the end of file with Fcntl? <aqumsieh@matrox.com>
    Re: Sending Perl output to 2 diffent html frames chad@vcn.net
    Re: Sending Perl output to 2 diffent html frames <dgris@moiraine.dimensional.com>
    Re: Simple sort required. (Tad McClellan)
    Re: Soft reference question <aqumsieh@matrox.com>
    Re: SPARC SOLARIS 2.5.1 PERL executables (Martien Verbruggen)
        squashing multiple blank lines into one <guadomatic@hotmail.com>
    Re: Statistics & Perl (Martien Verbruggen)
    Re: testing for scalar/list/array <aqumsieh@matrox.com>
    Re: testing for scalar/list/array (Martien Verbruggen)
    Re: testing for scalar/list/array (Martien Verbruggen)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 4 Feb 1999 22:48:21 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Readdir gives me garbage...
Message-Id: <slrn7bk92e.4g5.fl_aggie@PacificOcean.coaps.fsu.edu>

On Thu, 04 Feb 1999 20:03:09 GMT, panduh@eudoramail.com
<panduh@eudoramail.com> wrote:

+ Hi, I am trying to write a script that recursively runs through a
                                         ^^^^^^^^^^^
+ directory tree
  ^^^^^^^^^^^^^^

These three words always bring File::Find to mind...

James


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

Date: Fri, 05 Feb 1999 00:13:24 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Readdir gives me garbage...
Message-Id: <EIqu2.75$fP3.5222@nsw.nnrp.telstra.net>

In article <79cudl$4nu$1@nnrp1.dejanews.com>,
	panduh@eudoramail.com writes:

> Hi, I am trying to write a script that recursively runs through a
> directory tree two levels and grab the first level of subdirectories of

# perldoc File::Find

> a certain name and the files each subdirectory contains, of a certain
> name.  The code works, in general.. however for one particular directory
> it gives a huge load of garbage along with the filenames( like a whole
> bunch of /@/@/@/@/@/,misc. ASCII characters and filenames from other
> directories... )

Not without seeing the directories. You never check to see if the
thing you are opening is actually a directory. Are they maybe
symlinks? You should really consider checking some things now and
again, instead of assuming them.

> 
> # Open up the directory handle first
> opendir DIR, $LOG_DIR;

You should check the return value of _every_ system call. How do you
know it succeeded?


-- 
Martien Verbruggen                  | 
Interactive Media Division          | Little girls, like butterflies, need no
Commercial Dynamics Pty. Ltd.       | excuse - Lazarus Long
NSW, Australia                      | 


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

Date: Thu, 4 Feb 1999 13:26:49 -0500 
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Seek to the end of file with Fcntl?
Message-Id: <x3yg18mowig.fsf@tigre.matrox.com>


mkshanx@ust.hk writes:

> I am using Fcntl (file control) function (since I am running Solaris 2.4 which
> does not seem to support the flock()), and I need some help with "seek"ing to
> the EOF with Fcntl. The man pages do not help me much in figuring that out.

wouldn't a simple seek() do?

seek FH, 0, 2;



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

Date: Fri, 05 Feb 1999 00:31:35 GMT
From: chad@vcn.net
Subject: Re: Sending Perl output to 2 diffent html frames
Message-Id: <79de58$j0r$1@nnrp1.dejanews.com>

In article <xkfzp6thkz0.fsf@valdemar.col.hp.com>,
  Eric The Read <emschwar@mail.uccs.edu> wrote:
> "Bob Van Der Ploeg" <bob@worldparts.com> writes:
> > How do I get perl to send output to 2 different html frames?
>
> 1) You mean browser frames
> 2) You can't do that in Perl.
> 3) You can't do that.
> 4) You should talk to people in comp.infosystems.www.authoring.cgi,
>    probably.
>
> -=Eric

Of course you can do that.

You will have to trigger the CGI script from with-in each frame though.
Perl with a tiny bit of javascript will do the trick.

-chad

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 04 Feb 1999 18:02:01 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Sending Perl output to 2 diffent html frames
Message-Id: <m3d83p1x4m.fsf@moiraine.dimensional.com>

chad@vcn.net writes:

> Of course you can do that.

No, _you_ can't do that.  Only the user agent can do that.

You may have in mind some sort of hack that works with some
user agents in some circumstances, but we're not interested
in hearing about it, because it has nothing to do with perl.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: Thu, 4 Feb 1999 18:24:25 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Simple sort required.
Message-Id: <pndd97.5i7.ln@magna.metronet.com>

bazza2000@yahoo.com wrote:
: Can someone please help with this simple sort routine.  I'm new to perl and
: don't know the dynamics behind the sort function.  I've checked the FAQ's, but
: they seem either to brief or too complex.  For example none of them tell you
: what the $a and $b variables actually translate to from the input etc etc.


   All you need to know about sorting is that as some point, in
   whatever algorithm is used, you have to compare two items
   to determine their relative order.

   These comparisons happen often in the course of getting the
   stuff sorted.

   So you don't need to know the "dynamics" behind the function,
   you only need to figure out how to write the comparison
   function (or block) to end up with the order that you want.


: Anyway here the problem, I have an array of entries as follows:-

: @team_scores = { "name 1", 2 , "name 2", 5, "name 3" , 6} ;

: I want to get a sort function to put them back into an array on using the even
: positions in the array as the sort.  i.e. 2, 5 and 6 to be sorted accendingly
: leaving the following array


   Those are the odd positions not the even ones.

   Array indexing starts with zero.


: @team_scores = { "name 3", 6 , "name 2", 5, "name 1" , 2} ;
  ^              ^                                        ^
  ^              ^                                        ^

   You have a hybrid hash/array sort of thing going on there.

   Which are you using? A hash or an array?


: Anyone got any ideas,


   Your choice of data structure can have a profound impact on
   how hard it is to write the code that manipulates the data.

   You have chosen one that makes it hard. It is hard because
   you have no control over _which_ two elements will be
   compared (and that can vary depending on which sorting
   algorithm is used anyway).

   You should give serious consideration to revamping your 
   structure into something more helpful.


   What you have there looks to me to be screaming to be put
   into a hash with names for keys and scores for values. If
   you had that structure, then getting the sort order you want
   is laughingly simple in Perl:

     foreach (sort { $team_scores{$a} <=> $team_scores{$b}} keys %team_scores) {
        # print stuff in numerical order here
     }


   A couple other alternative stuctures that come to mind:

   1)
   use two parallel arrays

      @names  = ('name 3', 'name 2', 'name 1');
      @scores = (6, 5, 2);

   then you could just sort the indexes to realize the sort
   order that you want.


   2)
   use a list of lists where each inner list has the two elements
   (name and score)



   Getting it done with your data structure is more than
   I can get done in the 5 minutes max/post that I spend on news.

   Sorry.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 4 Feb 1999 12:28:32 -0500 
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: Soft reference question
Message-Id: <x3yiudioz7k.fsf@tigre.matrox.com>


rjk@linguist.dartmouth.edu (Ronald J Kimball) writes:

> 
> Lou Hevly <lou@visca.com> wrote:
> 
> > Ala Qumsieh <aqumsieh@matrox.com> wrote:
> > 
> > <snip>
> > 
> > >> open (UPLOAD, ">$updir") or die $!;
> > >> my ($Buffer);
> > >> while (read($upload,$Buffer,8192)) {
> > >             ^^^^^^^^^
> > >
> > >Your bug is here .. the first argument for read is a filehandle. You
> > >are using a variable. Although it is possible to use a variable as a
> > >filehandle, strict will not allow you to do that. Anyway, your script
> > >does not work even if you don't use strict because the read will fail.
> > 
> > I hate to contradict someone who knows more than I'll probably ever
> > know about Perl, but the fact is the script does work.

I know a lot of Perl, but not as much as I want to know. Even
then, I am sure I will still make mistakes. Please do correct (or
contradict) me if I'm wrong :)

> Ala is not familiar with CGI.pm's handling of file upload fields.
> CGI.pm's documentation states "The filename returned is also a file
> handle."  In other words, the first argument you are using in read()
> *is* a filehandle, which is why your code works fine.

That's true. I never used CGI.pm before.

> Note that until 5 minutes ago, I was not familiar with CGI.pm's handling
> of file upload fields either.  I found Ala's argument convincing until I
> searched the CGI.pm documentation for 'upload'.  :-)

That's one more thing I learnt today. One day I am planning to look
into CGI.pm. Until then, I'll avoid all web-related questions :)

Ala

PS. The other thing I learnt is that the range operators (.. and ...)
can be used in if() statements to extract lines that lie between two
specific lines in a file. No more temporary flags!

PPS. I always envied awk's range operator ( /PAT1/, /PAT2/ { } ) and
thought: "Why doesn't Perl support this!?" ... Now I see the bigger
picture.



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

Date: Thu, 04 Feb 1999 23:43:29 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: SPARC SOLARIS 2.5.1 PERL executables
Message-Id: <Bgqu2.67$fP3.5222@nsw.nnrp.telstra.net>

In article <36B977B5.D09606F6@ericsson.com>,
	Ericsson User <leo.alexandropoulos@ericsson.com> writes:

> I am looking for one of the latest releases of Perl executable(s) for
> SPARC Solaris 2.5.1..

www.sunfreeware.com

It would probably be better to get the gcc compiler from there, and
compile your own perl binaries. Even better: get a precompiled gcc.
Get the gcc sources. Compile your own gcc. get the perl sources.
Compile perl. More work, but worth it. Otherwise you'll always wonder
whether the stuff you're using is reliable.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | We are born naked, wet and hungry. Then
Commercial Dynamics Pty. Ltd.       | things get worse.
NSW, Australia                      | 


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

Date: Thu, 4 Feb 1999 15:35:04 -0800
From: "eric" <guadomatic@hotmail.com>
Subject: squashing multiple blank lines into one
Message-Id: <79dcsq$663@news.or.intel.com>

Hi,

This is really a sed question, but I didn't know where else
to post it.  Sorry!

I'm using the following to squash multiple blank lines into
one.

  /^[  ]*$/ {
   N
   N
   N
   N
   N
   N
   N
   N
   N
   N
   N
   N
   N
   N
   N
   N
   N
   s/\
*/\
/

But it's limited because it needs to know the most possible
blank lines it might encounter.  How else can I do this?

Eric




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

Date: Fri, 05 Feb 1999 00:04:11 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Statistics & Perl
Message-Id: <%zqu2.72$fP3.5222@nsw.nnrp.telstra.net>

In article <36B9A324.3A69E33E@golfway.com>,
	Ricardo Jardin <rjardin@golfway.com> writes:

> I created a log of statistics for each visit using Perl, the questions
> are :

visit using Perl? Oh.. I get it.. Never mind.

> 1.  On the log, can I tell which picture the reader " click's " on ?

I don't know. Is that information in the log? What sort of log is
this? What created it? What is the information in it? Didn't you just
say that _you_ created it, using Perl (comma is important)? If that is
true, then _you_ are the only one who can tell how to read the log,
and what information is contained in it.

> 2.  On the log also,  can I tell which banner or image with Perl Script
> that the
>       person clicks on ?

Perl Script? That is not Perl. What are you talking about?

Maybe you should just tell us:

- what the environment is

	We're using this and this web server on this and this platform,
	and everything has to be coded in Perl. (This last one is
	important, otherwise we will come over and drag you to
	comp.infosystems.www.*. Come to think of it, we will probably do
	that anyway, unless the question actually _is_ about perl, as
	opposed to just you thinking it is about perl.)
	This is a CGI question, yes, but I need to know how to code this
	in Perl. (answer: use CGI. Do it as you would do it in any other
	language. Go to ciwap (authoring.programming) to find out the
	techniques.

- what it is you want to accomplish

	- I want to put up a banner advertising, and need to keep track of
	  how often each banner comes up, and how often people actually
	  click on them.
	- I just want to know who clicks on which image, regardless of the
	  fact that none of my images are inside anchor tags, which is what
	  really matters
	- I want to keep track of everything a user does, once they have
	  visited my site. This includes number of clicks on my pages,
	  including wrong ones, number of pages they visit outside of my
	  site, how many MS products they own, how many times a day they
	  eat, what they eat, and when they fart.

- what you have tried

	- I haven't actually tried anything, because I can't program at all
	- I haven't tried anything, because I am lazy
	- I have tried installing one of Matt's scripts but they don't
	  work
	- I have tried writing some code but notepad won't let me save it
	- I have written the following code (code snippet), but for some
	  reason I am getting these error messages from perl (error
	  messages)
	- I haven't actually written any code, but I am looking through
	  the web access log files to see if I can get it from there.

- what you are prepared to pay

Have you considered having a look at www.cgi-resources.com to see if
someone maybe has dumped some code there that may do what you want?

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | The number of the beast is not 666. Its
Commercial Dynamics Pty. Ltd.       | number is 95, and it's awake.
NSW, Australia                      | 


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

Date: Thu, 4 Feb 1999 13:24:37 -0500 
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: testing for scalar/list/array
Message-Id: <x3yhft2owm2.fsf@tigre.matrox.com>


"Xah" <xah@best.com> writes:

> suppose f is a function, and it returns one of the following:
> * scalar. e.g. sub f() {return 3;};
> * a list. e.g. sub f() {return (99,28,57);};
> * an array. e.g. sub f() {my @a = (99,28,57); return @a;};
> 
> but you don't know which of these it returns.
> 
> What can I do to find out?

you can read the documentation.

perldoc -f wantarray

--Ala



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

Date: Thu, 04 Feb 1999 23:27:35 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: testing for scalar/list/array
Message-Id: <H1qu2.63$fP3.5222@nsw.nnrp.telstra.net>

In article <36b93dd1$0$16690@nntp1.ba.best.com>,
	"Xah" <xah@best.com> writes:

> suppose f is a function, and it returns one of the following:
> * scalar. e.g. sub f() {return 3;};
> * a list. e.g. sub f() {return (99,28,57);};
> * an array. e.g. sub f() {my @a = (99,28,57); return @a;};
> 
> but you don't know which of these it returns.

What a sub returns depends on the context, not on the return
statement.

# perldoc perlsub
# perldoc -f wantarray

You could execute it in a list context, and check the number of
elements in the list. Of course, if the function would have something
like 'return $a;' or 'return ($a):' you would not be able to tell the
difference. A sub returns one single flat list of scalars. Context is
provided to the subb to make decisions about how it wants to return
that.

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | I'm desperately trying to figure out
Commercial Dynamics Pty. Ltd.       | why kamikaze pilots wore helmets - Dave
NSW, Australia                      | Edison 


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

Date: Thu, 04 Feb 1999 23:41:34 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: testing for scalar/list/array
Message-Id: <Oequ2.66$fP3.5222@nsw.nnrp.telstra.net>

In article <36bb8c37.3701890@news.skynet.be>,
	bart.lateur@skynet.be (Bart Lateur) writes:

> Until I tested, I wasn't sure what the next will do. The result is, huh,
> "perlesk".

it is indeed...

surprising, but explainable :)

Martien
-- 
Martien Verbruggen                  | 
Interactive Media Division          | I think there is a world market for
Commercial Dynamics Pty. Ltd.       | maybe five computers. --Thomas Watson,
NSW, Australia                      | chairman IBM, 1943


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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