[9416] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3010 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 30 13:57:30 1998

Date: Tue, 30 Jun 98 10:43:02 -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           Tue, 30 Jun 1998     Volume: 8 Number: 3010

Today's topics:
        File::Find Symlink Problem <hellmann@vcc.de>
    Re: File::Find Symlink Problem <merlyn@stonehenge.com>
    Re: File::Find Symlink Problem <tchrist@mox.perl.com>
        filtering out garbage characters from post/get <jchance@cs.utexas.edu>
    Re: filtering out garbage characters from post/get <rootbeer@teleport.com>
    Re: filtering out garbage characters from post/get (Tad McClellan)
    Re: Find::File/Functional programing <scribble@pobox.com>
    Re: first language <bguen@StopSpamsprintmail.com>
    Re: flame everyone on sight (was Re: Perl and Delphi) <mgregory@asc.sps.mot.com>
        flock woes. (Alex Krohn)
    Re: flock woes. <rootbeer@teleport.com>
    Re: flock woes. (Mark-Jason Dominus)
    Re: flock woes. <tchrist@mox.perl.com>
    Re: Formatting integers with commas (1,000,000 etc.) (Mark-Jason Dominus)
        Functions In Perl <imo@vision.net.au>
    Re: Functions In Perl (Bob Trieger)
    Re: Functions In Perl <rra@stanford.edu>
    Re: Functions In Perl (Abigail)
    Re: Functions In Perl (Craig Berry)
    Re: Functions In Perl (Mark-Jason Dominus)
    Re: Functions In Perl (Mark-Jason Dominus)
    Re: Getting TEXTWIDTH from Perl (Josh Kortbein)
    Re: growing array size:  Is this a bug? (M.J.T. Guy)
        Gurus or perl hackers a quick question!! <JDobson@rnib.org.uk>
    Re: Gurus or perl hackers a quick question!! <bowlin@sirius.com>
    Re: Gurus or perl hackers a quick question!! <quednauf@nortel.co.uk>
    Re: Gurus or perl hackers a quick question!! (Charlie Stross)
    Re: Gurus or perl hackers a quick question!! (Larry Rosler)
    Re: Gurus or perl hackers a quick question!! (Tad McClellan)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Mon, 29 Jun 1998 16:35:46 +0200
From: Frank Hellmann <hellmann@vcc.de>
Subject: File::Find Symlink Problem
Message-Id: <3597A642.645546FA@vcc.de>

This is a multi-part message in MIME format.
--------------9BA1FF0F1ED296C0B40967E7
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi!

Is there any way to tell the File::Find function to follow symlinks,
like find(1) does with the
option -follow? find2perl does not recognize the -follow option, so
there is no hint.

Has anybody a brilliant though to get me on the right track again?

                                        Ciao,
                                                    Frank2

--
------------------------------------------------------------------------------
Frank Hellmann                VCC Vidco GmbH             Doormannsweg 43
System Administrator          http://www.vcc.de          20251 Hamburg
E-Mail: hellmann@vcc.de       Tel. +49 40 43169 203      Fax: ++49 40 4301789



--------------9BA1FF0F1ED296C0B40967E7
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Frank Hellmann
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Frank Hellmann
n:              Hellmann;Frank
org:            VCC VidCo GmbH
adr:            Doormannsweg 43;;;Hamburg;;20259;Germany
email;internet: hellmann@vcc.de
title:          System Administrator
tel;work:       ++49 40 43169 203
tel;fax:        ++49 40 4301789
x-mozilla-cpt:  ;0
x-mozilla-html: FALSE
version:        2.1
end:            vcard


--------------9BA1FF0F1ED296C0B40967E7--



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

Date: Mon, 29 Jun 1998 15:32:18 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: File::Find Symlink Problem
Message-Id: <8cd8bsz0ju.fsf@gadget.cscaper.com>

>>>>> "Frank" == Frank Hellmann <hellmann@vcc.de> writes:

Frank> Is there any way to tell the File::Find function to follow
Frank> symlinks, like find(1) does with the option -follow? find2perl
Frank> does not recognize the -follow option, so there is no hint.

Frank> Has anybody a brilliant though to get me on the right track again?

To follow symlinks, you have to make sure you're not going in circles.

One way is to track *every* dev/ino of everything you visit.  When
you see a symlink, get its dev/ino, and if it's not yet seen, added
it to the list of where you wanna go.  Maybe like this (untested):

	@visit = qw(/top/dir);
	while (@visit) {
		find \&wanted, shift @visit;
	}

	sub wanted {
		($dev,$ino) = stat;
		return if $seen{"$dev $ino"}++;
		if (-l && -d) {
			push @visit, "$File::Find::name/.";
		}
		... rest of wanted goes here ...
	}

Something like that should do it.  But no, that's not built into File::Find,
because, well, it isn't. :)

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 64 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 29 Jun 1998 17:07:11 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: File::Find Symlink Problem
Message-Id: <6n8hjv$5bu$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Randal Schwartz <merlyn@stonehenge.com> writes:
:		return if $seen{"$dev $ino"}++;

Normally that code is written

    return if $seen{$dev, $ino}++;

or

    unless unless $seen{$dev, $ino};

For example:

    #!/usr/bin/perl
    # manpath - compute manpath, with redundancy checking
    for (split(/:/, $ENV{'PATH'})) {
	next if /^\.?$/;
	s![^/+]*$!man! && -d && !$seen{$_}++ && do {
	    ($dev,$ino) = stat(_);
	    ! $seen{$dev,$ino}++
	} && push(@manpath,$_);
    }

    print join(":", @manpath), "\n";

For another example:

    #!/usr/bin/perl
    # dupfiles - find files that are the same with aliases
    foreach $filename (@ARGV) {
        ($dev, $ino) = stat $filename;
        push( @{ $seen{$dev,$ino} }, $filename);
    }

    foreach $devino (sort keys %seen) {
        ($dev, $ino) = split(/$;/o, $devino);
        if (@{$seen{$devino}} > 1) {
            # @{$seen{$devino}} is a list of filenames for the same file
        }
    }

--tom
-- 
Like Dennis' love note about rk05s, early Berkeley tapes cane with a
suggestion from Bill Joy that "this is a tape of bits," meaning there was no
guarantee of anything, and that complaints should be directed to /dev/null.
 --Andy Tannenbaum, "Politics of UNIX," Washington, DC USENIX Conference, 1984


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

Date: Mon, 29 Jun 1998 19:52:32 -0500
From: Jason Chancellor <jchance@cs.utexas.edu>
Subject: filtering out garbage characters from post/get
Message-Id: <359836CF.4739C083@cs.utexas.edu>

I have been able to filter out specific characters from a string using
the tr command,
but I want some way to filter out ALL characters except "a-Z" , "0-1"
and "space"

Im sure this is easy,  I just cant figure it out.

Help greatly appreciated.

  Jason



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

Date: Tue, 30 Jun 1998 03:24:34 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: filtering out garbage characters from post/get
Message-Id: <Pine.GSO.3.96.980629202408.17225E-100000@user2.teleport.com>

On Mon, 29 Jun 1998, Jason Chancellor wrote:

> I have been able to filter out specific characters from a string using
> the tr command, but I want some way to filter out ALL characters except
> "a-Z" , "0-1"  and "space" 

Maybe you want the /c option? Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 30 Jun 1998 00:02:47 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: filtering out garbage characters from post/get
Message-Id: <nhr9n6.466.ln@localhost>

Jason Chancellor (jchance@cs.utexas.edu) wrote:
: I have been able to filter out specific characters from a string using
: the tr command,
: but I want some way to filter out ALL characters except "a-Z" , "0-1"
: and "space"

: Im sure this is easy,  I just cant figure it out.


   s/[^a-zA-Z01 ]//g;


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


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

Date: 28 Jun 1998 14:26:04 -0500
From: Tushar Samant <scribble@pobox.com>
Subject: Re: Find::File/Functional programing
Message-Id: <6n65cc$7gr@tekka.wwa.com>

xah@shell13.ba.best.com writes:
>> > Is there a way to use File::Find with purely functional style programing?
>
>Someone sends me the answer.
>
>   find(sub{ myFunction($File::Find::name) }, 'path');

I gave you a perfectly usable answer. Get a separate sub to return
a closure, and then use that as an argument to find.

>Xah Lee wrote:
>> > I desire all my codes to be strickly "functional"...
>
>I think John Porter is right, that it's probably not a good idea to force
>oneself to functional programing in Perl... unless only for fun...

This specific concrete example isn't proving your sweeping abstract
statement with its yet to be determined meaning. Not that it matters
if you have already made up your mind about it...



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

Date: Mon, 29 Jun 1998 19:41:53 -0400
From: "Bill Guenthner" <bguen@StopSpamsprintmail.com>
Subject: Re: first language
Message-Id: <6n98kc$g5$1@birch.prod.itd.earthlink.net>

Hey Judson, I just defended you on the COBOL issue but this time you're
wrong.

Private Sub Form_GotFocus()
Form1.Print "hello world"
End Sub

The fact that "The user interfaces are *totally* different" has no bearing
on the language.
a Unix C++ or Visual C++ is still C++. BASIC is BASIC.

Judson McClendon wrote in message ...
>Bart Lateur wrote:
>>Judson McClendon wrote:
>>
>>> I can often write
>>>and run a small utility in BASIC before I could fire up my VC++ or VB
>>>compilers and begin coding.
>>
>>VB *is* BASIC. Very similar to QuickBasic, as you describe it.
>
>
>Hmmm.  Since I mentioned 'my VC++ or VB compilers...', perhaps you think
>I didn't know what VB is? ;-)  Actually VB is a GUI development system
>which supports a dialect of BASIC for writing what amount to macros,
>and which supports some OO concepts.  BASIC is a free-standing, purely
>procedural language, not embodying any OO concepts.  C and C++ are
>different languages, after all, are they not?  In other words, VB
>*includes* a *highly modified subset* of BASIC.  VB is *not* BASIC.  And
>if you think VB is 'very similar to QuickBasic', you couldn't possibly
>have used both.  It is true that some of the syntax is virtually identical,
>but QuickBasic and VB are far more different as a whole than say, Pascal
>and ALGOL.  The user interfaces are *totally* different, and way programs
>are structured is *totally* different.  If you are still unconvinced, just
>write a minimal 'Hello World!' program in both, print the entire source of
>each, and examine them.  Very little similarity, eh?  The text "Hello
>World!" itself is the only part which is even remotely the same.  8-)
>--
>Judson McClendon          This is a faithful saying and worthy of all
>Sun Valley Systems        acceptance, that Christ Jesus came into the
>judmc123@bellsouth.net    world to save sinners  (1 Timothy 1:15)
>(please remove numbers from email id to respond)
>
>
>




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

Date: 29 Jun 1998 10:31:18 +0930
From: Martin Gregory <mgregory@asc.sps.mot.com>
Subject: Re: flame everyone on sight (was Re: Perl and Delphi)
Message-Id: <r84sx5ggwx.fsf@asc.sps.mot.com>

abigail@fnx.com (Abigail) writes:

> Russell Schulz (Russell_Schulz@locutus.ofB.ORG) wrote on MDCCLX September
> MCMXCIII in <URL: news:19980626.124656.8g2.rnr.w164w_-_@locutus.ofB.ORG>:
> ++ Dan Nguyen <nguyend7@egr.msu.edu> writes:
> ++ 
> ++ >> Is the a library for Perl that can be run under Delphi?
> ++ >
> ++ > Why would you want to program in Delphi?
> ++ 
> ++ now, was there any reason for this?  or was it just incredibly poorly
> ++ stated?  did you mean:
> ++ 
> ++   whatever you can do in Delphi you can do in Perl, and easier
> 
> 
> I wouldn't mind programming in Delphi for a while.
> 
> 
> 
> Abigail
> -- 
> Greece isn't that bad.

ROTFL!!!!!  

(I wonder how many people saw that!)

Martin.




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

Date: Mon, 29 Jun 1998 20:10:45 GMT
From: alex@gossamer-threads.com (Alex Krohn)
Subject: flock woes.
Message-Id: <3597f229.2313497@coburg>

Here's a snippet of code I'm working with:

if ($in{$db_key} eq "random") {  # flock doesn't work here.
  my ($random_link) = -1;
  open  (URL, "<$db_url_name")   
     or &cgierr("unable to open url index $db_url_name. Reason: $!");
  if ($db_use_flock) {
    flock (URL, 2) 
      or &cgierr("unable to get exclusive lock. Reason: $!");
    }			
   @lines = <URL>;
   close URL;
   srand;
   ...
}
else {   # flock works here.
  open  (URL, "+>>$db_url_name")   
    or &cgierr("unable to open url index $db_url_name. Reason: $!");
  if ($db_use_flock) {
    flock (URL, 2) or 
      &cgierr("unable to get exclusive lock. Reason: $!");
  }
  seek  (URL, 0, 0);	  # rewind to begining.
  ...
  close URL;
}

Now the flock works if it goes through the else statement, but dies
with bad file number if it goes through the random statement. The only
reason I can think of is that the file handle was opened for reading
in the random statement, and for write (and read) in the else
statement.

Should this make a difference? Shouldn't you want to flock a file even
if it is for reading as you might catch the file in mid write and not
get the whole thing?

Also, this seems to be system dependant as it has worked on my machine
but not on some others (all Unix though).

Any ideas would really be appreciated..

Thanks,

Alex


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

Date: Mon, 29 Jun 1998 21:50:31 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: flock woes.
Message-Id: <Pine.GSO.3.96.980629144828.28620M-100000@user2.teleport.com>

On Mon, 29 Jun 1998, Alex Krohn wrote: 

> Now the flock works if it goes through the else statement, but dies with
> bad file number if it goes through the random statement. The only reason
> I can think of is that the file handle was opened for reading in the
> random statement, and for write (and read) in the else statement. 
> 
> Should this make a difference? Shouldn't you want to flock a file even
> if it is for reading as you might catch the file in mid write and not
> get the whole thing? 

You can use a shared lock if you're merely reading. After all, you can let
others read at the same time, right? 

> Also, this seems to be system dependant as it has worked on my machine
> but not on some others (all Unix though). 

What, aren't all Unices the same? :-) 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/




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

Date: 29 Jun 1998 21:49:44 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: flock woes.
Message-Id: <6n9g7o$goa$1@monet.op.net>



    I seem to remember that on some systems you can't exclusive-lock a
file unless you opened it for writing.  That's stupid, but there it
is.

    Try using a shared lock instead.  The flock will still fail if
another instance of the program has the file exclusive-locked, and
vice versa.  On the other hand, using a shared lock will allow several
processes to read the file simultaneously, which can't hurt.



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

Date: 30 Jun 1998 01:57:46 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: flock woes.
Message-Id: <6n9gmq$j2r$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    mjd@op.net (Mark-Jason Dominus) writes:
:    I seem to remember that on some systems you can't exclusive-lock a
:file unless you opened it for writing.  That's stupid, but there it
:is.

In fact, badly derived SysV ones that make perl use lockf
on the underside are like this.  AIX is the most likely 
culprit, but one might also look carefully at Irix and hpux.

--tom
-- 
    "What is the sound of Perl?  Is it not the sound of a wall that
     people have stopped banging their heads against?"
		--Larry Wall in <1992Aug26.184221.29627@netlabs.com>


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

Date: 28 Jun 1998 13:06:55 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Formatting integers with commas (1,000,000 etc.)
Message-Id: <6n5t7f$6kp$1@monet.op.net>
Keywords: knell loblolly morose textile


In article <35942A6B.37005E07@bellacoola.com>,
John Charlesworth  <jcharlesworth@bellacoola.com> wrote:
>Anyone know a simple idiom for inserting the commas?  


	use Interpolation ',' => 'commify';

	$SALARY = 142857.5;
	print "My salary is $,{$SALARY}\n"; 

	# Prints ``My salary is 142,857.50''





Interpolation: <URL:http://www.plover.com/~mjd/perl/Interpolation/>


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

Date: Sun, 28 Jun 1998 13:00:10 +1000
From: "John" <imo@vision.net.au>
Subject: Functions In Perl
Message-Id: <6n4biu$fmk$1@pandora.vision.net.au>

Just wondering, are functions in Perl the same as C++?

Could some one please show me some sample code, or point me to some?

Thanks,
John




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

Date: Sun, 28 Jun 1998 03:15:38 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: Functions In Perl
Message-Id: <6n4ckh$vlk$2@strato.ultra.net>

[ posted and mailed ]

"John" <imo@vision.net.au> wrote:
-> Just wondering, are functions in Perl the same as C++?

No, they are much more user friendly.

-> Could some one please show me some sample code, or point me to some?

The net is littered with perl source. Check out Yahoo.

Your best bet is to start at http://www.perl.com/ you can find out everything 
you ever wanted to know there.

HTH

Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-286-0591
  and let the jerk that answers know that his
  toll free number was sent as spam. "


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

Date: 27 Jun 1998 20:29:33 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Functions In Perl
Message-Id: <m3hg1619wi.fsf@windlord.Stanford.EDU>

John <imo@vision.net.au> writes:

> Just wondering, are functions in Perl the same as C++?

No, not really, but they may be similar in the respects that you're
wondering about.  I'm afraid that without some more detail to the
question, I can't give you much of an answer.

> Could some one please show me some sample code, or point me to some?

Sample Perl code?  There's a lot that comes with the standard Perl
distribution, people post excerpts to this group all the time, and you
should be able to find any number of packages available on the web or via
ftp that were written in Perl.  The code quality will vary, of course.

Hope this helps!

-- 
#!/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: 28 Jun 1998 04:23:37 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Functions In Perl
Message-Id: <6n4gg9$62s$10@client3.news.psi.net>

John (imo@vision.net.au) wrote on MDCCLXII September MCMXCIII in
<URL: news:6n4biu$fmk$1@pandora.vision.net.au>:
++ Just wondering, are functions in Perl the same as C++?

No.



Abigail
-- 
perl -we '$_ = q ?4a75737420616e6f74686572205065726c204861636b65720as?;??;
          for (??;(??)x??;??)
              {??;s;(..)s?;qq ?print chr 0x$1 and \161 ss?;excess;??}'


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

Date: 28 Jun 1998 06:00:43 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Functions In Perl
Message-Id: <6n4m6b$kgm$1@marina.cinenet.net>

John (imo@vision.net.au) wrote:
: Just wondering, are functions in Perl the same as C++?

No.  Yes.  It depends.  How do you define 'same'?  They have in common
being named pieces of code that can accept parameters and return values.
They differ significantly in details of syntax and semantics.

: Could some one please show me some sample code, or point me to some?

Your best bet is almost certainly the book _Learning Perl_ (Schwartz and
Christiansen).  Failing that, read the free online doc, watch this group
for code examples, and experiment.

Here's a minimal Perl subroutine, commented to show its parts:

  sub times2         # sub keyword starts a function, followed by name
  {                  # {} braces wrap body of function
    2 * shift;       # Perl magic -- shift pulls off the argument
                     #  from @_ (the list of arguments).  The last
                     #  expression evaluated in the function's
                     #  execution gets returned as its value.
  }

Hope this helps!

---------------------------------------------------------------------
   |   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: 28 Jun 1998 12:55:32 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Functions In Perl
Message-Id: <6n5si4$6i6$1@monet.op.net>

In article <6n4biu$fmk$1@pandora.vision.net.au>,
John <imo@vision.net.au> wrote:
>Just wondering, are functions in Perl the same as C++?

Yes in some ways, but not in others.


>Could some one please show me some sample code, or point me to some?

Perl comes with on-line documentation.  The `perlsub' file discusses
subroutnines in detail.  On Unix systems, use

	perldoc perlsub
or	man perlsub

On other machines, locate the `perlsub.pod' file and view it with a
word processor or do whatever is appropriate for your platofrm.

The manual is available from many places on the web; try a web search
for `perlsub'.

Anotehr alternative:  Perl comes with many, many code samples, all of
which are full of subroutines.  Just poke around in your perl
distribution.

If you can't understand the manual, get the book `Learning Perl' by
Schwartz, and read it.


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

Date: 28 Jun 1998 16:43:03 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Functions In Perl
Message-Id: <6n69sn$7ni$1@monet.op.net>


In article <6n5si4$6i6$1@monet.op.net>, Mark-Jason Dominus <mjd@op.net> wrote:
>If you can't understand the manual, get the book `Learning Perl' by
>Schwartz, and read it.

Schwartz and Christiansen.




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

Date: 30 Jun 1998 15:38:30 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Re: Getting TEXTWIDTH from Perl
Message-Id: <6nb0pm$kp7$3@news.iastate.edu>

Tim (tim@paco.net) wrote:
: Hi!

: Sorry for my english.

: You now that default 'Times' font used by browsers has different width
: of characters and string of ten 'I' much shorter than string of ten
: 'W'. The question is how to determine width of string to correctly fit
: it in table cell without wrap? Or I need to create array with
: approximate width of each char and then calculate width? Too slow, I
: think...

You're using a web browser. You're not meant to have that amount
of control over the presentation of content in a browser window.



Josh

--

_________________________________________________________
I do not trust your bitch.
	- Frederich Nietzche, in _Also Sprach Zarathustra_



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

Date: 29 Jun 1998 09:05:15 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: growing array size:  Is this a bug?
Message-Id: <6n7lcb$gp7$1@pegasus.csx.cam.ac.uk>

unknown <kesey@globe.ece.utexas.edu> wrote:
>
>The problem is that the size of the list grows due to the function call
>
>  &someSub (3, $arr[9]);
>
>I thought that referring to an list element past the end of the list
>does not increase the size of the list.

This bug is mended in Perl versions 5.004 and later.   Upgrade.

>An unrelated problem I found is that the 'sort' using the undefined
>list element causes a segmentation fault on my system.

Current Perls use the system provided qsort() to implement sort.
On some platforms, this can SEGV if you give it a comparison function
which doesn't define an ordering.

THe next maintenance release of Perl (5.004_05) will have its own sort
code, which should be immune from this problem.

But the mere presence of `undef' in the data to be sorted shouldn't
provoke this.   So you may have some other bug.   Again, see if it goes
away on an upgrade.


Mike Guy


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

Date: Tue, 30 Jun 1998 16:02:22 +0100
From: James Dobson <JDobson@rnib.org.uk>
Subject: Gurus or perl hackers a quick question!!
Message-Id: <3598FDFE.5DE194B7@rnib.org.uk>

Rather than reinvent the wheel I was wondering if you know the PERL
script to read a line like "1 > Mr X - X@X - Male" and just extract the
Mr X part or the X@X part?

Each line has a individual number so it would be easy to identify a
line. Just though I'd ask so I can compare my method (which is to
bulky!:-( ).

James




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

Date: Tue, 30 Jun 1998 08:32:44 -0700
From: Jim Bowlin <bowlin@sirius.com>
To: James Dobson <JDobson@rnib.org.uk>
Subject: Re: Gurus or perl hackers a quick question!!
Message-Id: <3599051C.8139C5D3@sirius.com>

James Dobson wrote:
> 
> Rather than reinvent the wheel I was wondering if you know the PERL
> script to read a line like "1 > Mr X - X@X - Male" and just extract the
> Mr X part or the X@X part?
> 
> Each line has a individual number so it would be easy to identify a
> line. Just though I'd ask so I can compare my method (which is to
> bulky!:-( ).
> 
> James

while(<>) {
    /^\d+\s*>\s*([^\-]*) - ([^\-]*) - (.*)/ or next;
    my $name  = $1;
    my $addr  = $2;
    my $other = $3;
    ...
}

-- Jim Bowlin


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

Date: Tue, 30 Jun 1998 16:34:56 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: Gurus or perl hackers a quick question!!
Message-Id: <359905A0.F9911F73@nortel.co.uk>

James Dobson wrote:
> 
> Rather than reinvent the wheel I was wondering if you know the PERL
> script to read a line like "1 > Mr X - X@X - Male" and just extract the
> Mr X part or the X@X part?
> 
eg

$_ = '1 > Mr X - X@X - Male';

($line, $rest) = split(/>/);
($name, $thing, $gender) = split(/-/, $rest);

print "$line ::: $name,$thing,$gender\n";


-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: Tue, 30 Jun 1998 16:18:26 GMT
From: charlie@antipope.org (Charlie Stross)
Subject: Re: Gurus or perl hackers a quick question!!
Message-Id: <slrn6pi3va.23c.charlie@cs.ed.datacash.com>

In the name of Kibo the Compassionate, the Merciful,
on Tue, 30 Jun 1998 16:02:22 +0100,James Dobson
the supplicant <JDobson@rnib.org.uk> implored:

>Rather than reinvent the wheel I was wondering if you know the PERL
>script to read a line like "1 > Mr X - X@X - Male" and just extract the
>Mr X part or the X@X part?
>
>Each line has a individual number so it would be easy to identify a
>line. Just though I'd ask so I can compare my method (which is to
>bulky!:-( ).

Howzabout ...

foreach (<>) {
   my (@bits) = split(/\s+?-\s+?/, $_);
   my ($junk, $name) = split(/\s+?>\s+?/, $bits[0]);
   $names{$name} = $bits[1];
}

First, we split the incoming line ($_) on a regular expression 
consisting of whitespace, a dash, then more whitespace. Each field
ends up somewhere in the array @bits.

(NB: the last field also has a newline, but as we're going to throw it
away we don't bother chomp()'ing it.)

 ext, we split the first element of the @bits array ("1 > Mr X") on
whitespace, >, whitespace. We assign the results (two elements, a
line number and a name) into a list containing two variables, one of 
which is junk.

We now stick the output in a hash, %names, where each key is a name 
(Mr X) and each value is an address (the X@X bit).

Example:

-- snip -- data file --
1 > Mr A - X@A - Male
2 > Mr B - X@B - Male
3 > Mr C - X@C - Male
4 > Mr D - X@D - Male
5 > Mr E - X@E - Male
-- snip -- program --

foreach (<>) {
   my (@bits) = split(/\s+?-\s+?/, $_);
   my ($junk, $name) = split(/\s+?>\s+?/, $bits[0]);
   $names{$name} = $bits[1];
}

foreach (keys %names) {
      print "$_ -> $names{$_}\n";
}
-- snip -- end --

Run the program on the data file and you get the following output:

# ./test2 <data
Mr A -> X@A
Mr B -> X@B
Mr C -> X@C
Mr D -> X@D
Mr E -> X@E  

However, there are about a billion other ways of doing this. For
example, we can transform the pesky ">" into another dash and get
rid of the second split:

foreach (<>) {
    $_ =~ tr/>/-/;
    my (@bits) = split(/\s+?-\s+?/, $_);
    $names{$bits[1]} = $bits[2];
}

We could shorten this another way by using split on a regular
expression:

foreach (<>) {
     my (@bits) = split(/\s+?[-\>]\s+?/, $_);
     $names{$bits[1]} = $bits[2];
} 

(Here we've told split() to use either a dash _or_ a ">" surrounded by
whitespace as a field boundary to split on.)

Or we could take an entirely different approach and use regular expressions 
instead of split:

foreach (<>) {
    ($name, $addr) = ($_ =~ /
        ^\d+?\s+?>\s+  # digits, spaces, ">", spaces
        ([\w\s]+?)     # minimal run of letters'n'spaces
        \s+?-\s+?      # spaces, dash, spaces
        (\w+@\w+)      # letters, @, letters
        \s+?-\s+?      # spaces, dash, spaces
        [\s\w]+?$      # word or space characters to end of line
    /xi);
    $names{$name} = $addr;
}
 
(NB: the regular expression above is excessively detailed and is opened
up using the /i flag to make it more readable. Nope, I can't be bothered
to shorten this for you ... :).

There are about a billion other ways of tackling this problem, and 
someone will probably waltz in now and demonstrate how to do it in
half a line.

This is the first lesson of perl; There's More Than One Way To Do It.



-- Charlie



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

Date: Tue, 30 Jun 1998 09:38:27 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Gurus or perl hackers a quick question!!
Message-Id: <MPG.1002b4636508debc989707@nntp.hpl.hp.com>

In article <slrn6pi3va.23c.charlie@cs.ed.datacash.com> on Tue, 30 Jun 
1998 16:18:26 GMT, Charlie Stross <charlie@antipope.org> says...
 ...<snip of much too much Perl code, etc., without further comment>
> foreach (<>) {
>     ($name, $addr) = ($_ =~ /

Perl style is to leave out the default $_ =~ here (and the parens around 
the regex are unnecessary too).

>         ^\d+?\s+?>\s+  # digits, spaces, ">", spaces
>         ([\w\s]+?)     # minimal run of letters'n'spaces
>         \s+?-\s+?      # spaces, dash, spaces
>         (\w+@\w+)      # letters, @, letters
>         \s+?-\s+?      # spaces, dash, spaces
>         [\s\w]+?$      # word or space characters to end of line
>     /xi);
>     $names{$name} = $addr;
> }
>  
> (NB: the regular expression above is excessively detailed and is opened
> up using the /i flag to make it more readable. Nope, I can't be bothered
> to shorten this for you ... :).

/i has to do with case-insensitivity, and is unnecessary in this regex.  
Surely you meant the /x flag to make it more readable.

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 30 Jun 1998 11:50:23 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Gurus or perl hackers a quick question!!
Message-Id: <f05bn6.dsf.ln@localhost>

James Dobson (JDobson@rnib.org.uk) wrote:
: Rather than reinvent the wheel I was wondering if you know the PERL
: script to read a line like "1 > Mr X - X@X - Male" and just extract the
: Mr X part or the X@X part?

: Each line has a individual number so it would be easy to identify a
: line. Just though I'd ask so I can compare my method (which is to
: bulky!:-( ).
  ^^^^^


In this case it would seem that more than one line is "bulky"  ;-)


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

$_ = '1 > Mr X - X@X - Male';

($number, $name, $address, $sex) = split / [>-] /;

print "number:  '$number'\n";
print "name:    '$name'\n";
print "address: '$address'\n";
print "sex:     '$sex'\n";
------------------


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


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

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

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