[19086] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1281 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 11 03:57:09 2001

Date: Wed, 11 Jul 2001 00:56:44 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <994838204-v10-i1281@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 11 Jul 2001     Volume: 10 Number: 1281

Today's topics:
        trimming blank <pascalleprevost@canada.com>
    Re: trimming blank <holland@origo.ifa.au.dk>
    Re: trimming blank (Brian Pontz)
    Re: trimming blank <EvR@compuserve.com>
    Re: trimming blank <EvR@compuserve.com>
    Re: trimming blank (Brian Pontz)
    Re: trimming blank <holland@origo.ifa.au.dk>
    Re: trimming blank <EvR@compuserve.com>
    Re: trimming blank (Craig Berry)
    Re: trimming blank (Craig Berry)
    Re: trimming blank (Craig Berry)
    Re: trimming blank <holland@origo.ifa.au.dk>
    Re: trimming blank <mjcarman@home.com>
    Re: trimming blank <holland@origo.ifa.au.dk>
    Re: trimming blank <dbe@wgn.net>
        trying to install perl on Alpha (David Storrs)
    Re: trying to install perl on Alpha <dan@tuatha.sidhe.org>
        turn off redirect in LWP? <osass@ix.urz.uni-heidelberg.de>
    Re: turn off redirect in LWP? (Rafael Garcia-Suarez)
    Re: variable require <pne-news-20010709@newton.digitalspace.net>
        Very good regex question? <scott@remove.generator.co.za>
    Re: Very good regex question? <scott@remove.generator.co.za>
    Re: Very good regex question? <wyzelli@yahoo.com>
    Re: Very good regex question? <wyzelli@yahoo.com>
    Re: What is the best way to get the size of file <pr_NOSPAM_lx@m*NOSPAM*ac.com>
    Re: What is the best way to get the size of file nobull@mail.com
    Re: What is the best way to get the size of file <krahnj@acm.org>
    Re: Why 1st line always mising. <goldbb2@earthlink.net>
    Re: Why does this hash work? %h->{a}='v' nobull@mail.com
    Re: Why does this hash work? %h->{a}='v' (Mark Jason Dominus)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Jul 2001 17:03:22 GMT
From: "Pascal" <pascalleprevost@canada.com>
Subject: trimming blank
Message-Id: <uzG27.26803$MO1.3773060@news0.telusplanet.net>

What is the best way to remove spaces before or after a sentence.

Example before: "             Hello World          "
Example after: "Hello World"

I appreciate any help.  Thanks
--
Pascal Leprevost
Winsoft Solutions Ltd.
winsoft@canda.com




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

Date: 10 Jul 2001 19:31:35 +0200
From: Steve Holland <holland@origo.ifa.au.dk>
Subject: Re: trimming blank
Message-Id: <w47hewk4rns.fsf@origo.ifa.au.dk>

"Pascal" <pascalleprevost@canada.com> writes:

> What is the best way to remove spaces before or after a sentence.
> 
> Example before: "             Hello World          "
> Example after: "Hello World"

     This may not be the most efficient method, but it works.

#! /usr/local/bin/perl -TW
use strict;
my $s = "             Hello World          ";
$s =~ s/^\s+(.+)\b\s+$/\1/;


=====================================================================
               To find out who and where I am look at:
               http://www.nd.edu/~sholland/index.html
=====================================================================


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

Date: Tue, 10 Jul 2001 17:33:42 GMT
From: pontz@NO_SPAMchannel1.com (Brian Pontz)
Subject: Re: trimming blank
Message-Id: <3b4b3bf7.32735363@news.ne.mediaone.net>

>Example before: "             Hello World          "
>Example after: "Hello World"

This seemed to work

#!/usr/bin/perl
use strict;
my $string = '  Hello World   ';
$string =~ s/^\s+(.*)\s+$/$1/;
print "$string\n";

Brian


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

Date: Tue, 10 Jul 2001 11:44:17 -0600
From: "Richard A. Evans" <EvR@compuserve.com>
Subject: Re: trimming blank
Message-Id: <9ifes6$q9q$1@suaar1ac.prod.compuserve.com>

> What is the best way to remove spaces before or after a sentence.
>
> Example before: "             Hello World          "
> Example after: "Hello World"
>

  $string = "             Hello World          ";
  $string =~ s/^\s+|\s+$//g;





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

Date: Tue, 10 Jul 2001 11:51:42 -0600
From: "Richard A. Evans" <EvR@compuserve.com>
Subject: Re: trimming blank
Message-Id: <9iff4o$qf3$1@suaar1ac.prod.compuserve.com>


"Brian Pontz" <pontz@NO_SPAMchannel1.com> wrote in message
news:3b4b3bf7.32735363@news.ne.mediaone.net...
> >Example before: "             Hello World          "
> >Example after: "Hello World"
>
> This seemed to work
>
> #!/usr/bin/perl
> use strict;
> my $string = '  Hello World   ';
> $string =~ s/^\s+(.*)\s+$/$1/;
> print "$string\n";
>
Actually I don't believe this works, as the .* is greedy and consumes the
trailing spaces.






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

Date: Tue, 10 Jul 2001 17:59:13 GMT
From: pontz@NO_SPAMchannel1.com (Brian Pontz)
Subject: Re: trimming blank
Message-Id: <3b4b4216.34303166@news.ne.mediaone.net>

>Actually I don't believe this works, as the .* is greedy and consumes the
>trailing spaces.

You are correct. I only checked it with one space after the string.
Not with multiple spaces.

Brian


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

Date: 10 Jul 2001 19:59:48 +0200
From: Steve Holland <holland@origo.ifa.au.dk>
Subject: Re: trimming blank
Message-Id: <w47d7784qcr.fsf@origo.ifa.au.dk>

"Richard A. Evans" <EvR@compuserve.com> writes:
> "Brian Pontz" <pontz@NO_SPAMchannel1.com> wrote:

> > >Example before: "             Hello World          "
> > >Example after: "Hello World"

> > This seemed to work
> >
> > #!/usr/bin/perl
> > use strict;
> > my $string = '  Hello World   ';
> > $string =~ s/^\s+(.*)\s+$/$1/;
> > print "$string\n";

> Actually I don't believe this works, as the .* is greedy and
> consumes the trailing spaces.

     It does not.  When I run it using perl v5.6.0 I get "Hello World
".  It needs a \b before the final set of spaces so that .* stops
matching when it reaches the end of the final word.


=====================================================================
               To find out who and where I am look at:
               http://www.nd.edu/~sholland/index.html
=====================================================================




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

Date: Tue, 10 Jul 2001 12:13:16 -0600
From: "Richard A. Evans" <EvR@compuserve.com>
Subject: Re: trimming blank
Message-Id: <9ifgct$rbd$1@suaar1ac.prod.compuserve.com>


"Steve Holland" <holland@origo.ifa.au.dk> wrote in message
news:w47d7784qcr.fsf@origo.ifa.au.dk...
> "Richard A. Evans" <EvR@compuserve.com> writes:
> > "Brian Pontz" <pontz@NO_SPAMchannel1.com> wrote:
>
> > > >Example before: "             Hello World          "
> > > >Example after: "Hello World"
>
> > > This seemed to work
> > >
> > > #!/usr/bin/perl
> > > use strict;
> > > my $string = '  Hello World   ';
> > > $string =~ s/^\s+(.*)\s+$/$1/;
> > > print "$string\n";
>
> > Actually I don't believe this works, as the .* is greedy and
> > consumes the trailing spaces.
>
>      It does not.  When I run it using perl v5.6.0 I get "Hello World
> ".  It needs a \b before the final set of spaces so that .* stops
> matching when it reaches the end of the final word.
>
>
That's one approach, but (as in my other post), I think the easiest way is:

  $string = "             Hello World          ";
  $string =~ s/^\s+|\s+$//g;





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

Date: Tue, 10 Jul 2001 18:15:40 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: trimming blank
Message-Id: <tkmhicsfn04red@corp.supernews.com>

Pascal (pascalleprevost@canada.com) wrote:
: What is the best way to remove spaces before or after a sentence.
: 
: Example before: "             Hello World          "
: Example after: "Hello World"

perldoc -q strip

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Brute force done fast enough looks slick."
   |             - William Purves


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

Date: Tue, 10 Jul 2001 18:25:11 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: trimming blank
Message-Id: <tkmi47307feo89@corp.supernews.com>

Steve Holland (holland@origo.ifa.au.dk) wrote:
: "Pascal" <pascalleprevost@canada.com> writes:
: > What is the best way to remove spaces before or after a sentence.
:
:      This may not be the most efficient method, but it works.
:
: #! /usr/local/bin/perl -TW
: use strict;
: my $s = "             Hello World          ";
: $s =~ s/^\s+(.+)\b\s+$/\1/;

It's not merely inefficient, but broken.  First, use of \1 rather than $1
on the substitution side earns you a warning.  Second, try feeding this
the string ' A sentence. ' and see what happens.

As usual, the faq (perldoc -q strip) provides a much better answer, if the
OP's 'sentence' is equivalent to a single scalar.  If the problem involves
parsing sentences out of free-format text, it is effectively impossible to
solve in the most general case, though reasonably good heuristics exist.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Brute force done fast enough looks slick."
   |             - William Purves


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

Date: Tue, 10 Jul 2001 18:29:07 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: trimming blank
Message-Id: <tkmibj3d0enace@corp.supernews.com>

Brian Pontz (pontz@NO_SPAMchannel1.com) wrote:
: >Example before: "             Hello World          "
: >Example after: "Hello World"
: 
: This seemed to work

Why do people post things that 'seem to work', rather than (a) testing
them, or (b) checking the FAQ?

: #!/usr/bin/perl
: use strict;
: my $string = '  Hello World   ';
: $string =~ s/^\s+(.*)\s+$/$1/;
: print "$string\n";

Make that last line

  print "|$string|\n";

and you may get a small surprise.  Greed is to blame, as usual. :)
Note that even if you fix the greediness problem, there is a further issue
involving how you've quantified the \s matches.  Spaces will be trimmed
only if there are spaces found at *both* the front and the back of the
string.

As usual, the FAQ gets this right:  'perldoc -q strip'

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Brute force done fast enough looks slick."
   |             - William Purves


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

Date: 10 Jul 2001 20:37:09 +0200
From: Steve Holland <holland@origo.ifa.au.dk>
Subject: Re: trimming blank
Message-Id: <w477kxg4omi.fsf@origo.ifa.au.dk>

cberry@cinenet.net (Craig Berry) writes:

> Why do people post things that 'seem to work', rather than (a)
> testing them,

     People usually do test, but not for enough cases.  All of the
solutions that have been posted work for some test cases.


=====================================================================
               To find out who and where I am look at:
               http://www.nd.edu/~sholland/index.html
=====================================================================


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

Date: Tue, 10 Jul 2001 12:55:16 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: trimming blank
Message-Id: <3B4B4184.68853158@home.com>

Steve Holland wrote:
> 
> "Pascal" <pascalleprevost@canada.com> writes:
> 
> > What is the best way to remove spaces before or after a sentence.
> >
> > Example before: "             Hello World          "
> > Example after: "Hello World"
> 
>      This may not be the most efficient method, but it works.
> 
> #! /usr/local/bin/perl -TW
> use strict;
> my $s = "             Hello World          ";
> $s =~ s/^\s+(.+)\b\s+$/\1/;

It isn't, and it doesn't for all cases. What if $s = 'Hello World ' (no
leading space)? What if it contains an embedded newline? Also, use of \1
is kind of discouraged, unless you're one of those folks for whom the
"compatible" syntax was provided. $1 is preferred.

The correct answer is given in the FAQ, which should always be consulted
*before* posting. :)

perldoc -q space

-mjc


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

Date: 10 Jul 2001 20:57:23 +0200
From: Steve Holland <holland@origo.ifa.au.dk>
Subject: Re: trimming blank
Message-Id: <w474rsk4nos.fsf@origo.ifa.au.dk>

Michael Carman <mjcarman@home.com> writes:
> Steve Holland wrote:
> > "Pascal" <pascalleprevost@canada.com> writes:

> > > What is the best way to remove spaces before or after a sentence.

> > > Example before: "             Hello World          "
> > > Example after: "Hello World"

> >      This may not be the most efficient method, but it works.

> > #! /usr/local/bin/perl -TW
> > use strict;
> > my $s = "             Hello World          ";
> > $s =~ s/^\s+(.+)\b\s+$/\1/;

> It isn't, and it doesn't for all cases. What if $s = 'Hello World '
> (no leading space)? What if it contains an embedded newline? Also,
> use of \1 is kind of discouraged, unless you're one of those folks
> for whom the "compatible" syntax was provided. $1 is preferred.
 
     The /1 was a typo.  I still tend to miss that one every now and
then.  It's yet another reason to always use -TW in the command line.

=====================================================================
               To find out who and where I am look at:
               http://www.nd.edu/~sholland/index.html
=====================================================================


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

Date: Tue, 10 Jul 2001 17:41:07 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: trimming blank
Message-Id: <3B4BA0A3.E0524555@wgn.net>

Pascal wrote:
> 
> What is the best way to remove spaces before or after a sentence.
> 
> Example before: "             Hello World          "
> Example after: "Hello World"

Fastest way is probably to use two REs:

 $string = "             Hello World          ";
 $string =~ s/^\s+//;
 $string =~ s/\s+$//;

This one suggested earlier is nice and simple:

 $string =~ s/^\s+|\s+$//g;



-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.webjump.com/ (Free Perl site)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


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

Date: 10 Jul 2001 08:41:34 -0700
From: dstorrs@dstorrs.com (David Storrs)
Subject: trying to install perl on Alpha
Message-Id: <207f25a5.0107100741.57545d07@posting.google.com>

I've never tried to install perl from source before, and I'm not
having
much luck...I downloaded the source (stable.tar.gz), ran Configure,
and
tried to do the 'make', 'make test', 'make install'
series.  Unfortunately, it bombs out on 'make', with the following
output:

################### BEGIN OUTPUT OF 'make'
        AutoSplitting perl library
LD_LIBRARY_PATH=/usr/rz4/users/paulm/perl-5.6.1:/usr/rz1/odi_6.0.SP4/ostore/lib:/usr/rz1/odi_6.0.SP4/osji/lib:/usr/users/paulm/prac\
tice/jni ./miniperl -Ilib -e 'use
AutoSplit;  autosplit_lib_modules(@ARGV)' lib/*.pm lib/*/*.pm

        Making DynaLoader (static)
Can't locate File/Glob.pm in @INC (@INC contains: ../../lib
/usr/users/paulm/perl5_6_1/lib/5.6.1/alpha-dec_osf
/usr/users/paulm/per\
l5_6_1/lib/5.6.1
/usr/users/paulm/perl5_6_1/site_perl/lib/site_perl/5.6.1/alpha-dec_osf
/usr/users/paulm/perl5_6_1/site_perl/lib/si\
te_perl/5.6.1 /usr/users/paulm/perl5_6_1/site_perl/lib/site_perl .
 .)BEGIN
failed--compilation aborted at (eval 70) line 7.
 at ../../lib/ExtUtils/MakeMaker.pm line 507
Warning: No Makefile!
Make: Don't know how to make config.  Stop.
make config failed, continuing anyway...
Make: Don't know how to make all.  Stop.
*** Exit 1
Stop.

################### END OUTPUT OF 'make'

I'm trying to install this on an Alpha, OSF1 V4.0 1229.  I do not have
root on this box, so I'm trying to install to a subdir of ~.  There
_is_ a
prior version of perl installed, but it's 5.002...full output of perl
-V:

####################### BEGIN OUTPUT OF 'perl -V'

Summary of my perl5 (5.0 patchlevel 2) configuration:
  Platform:
    osname=dec_osf, osver=3.2, archname=alpha-dec_osf
    uname='osf1 ahnkenaten.adone.com v3.2 41.64 alpha '
    hint=recommended, useposix=true
  Compiler:
    cc='cc', optimize='-O2 -Olimit 2900', gccversion=
    cppflags='-DSTANDARD_C -I/usr/local/include -D__LANGUAGE_C__
-D_NO_PROTO'
    ccflags ='-DSTANDARD_C -I/usr/local/include -D__LANGUAGE_C__
-D_NO_PROTO'
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
    intsize=4, alignbytes=8, usemymalloc=y, randbits=15
  Linker and Libraries:
    ld='ld', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /usr/shlib /lib /usr/lib /usr/ccs/lib
    libs=-ldbm -lm -lc -lbsd -lPW
    libc=/usr/shlib/libc.so, so=so
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags=' '
    cccdlflags=' ', lddlflags='-shared -expect_unresolved "*" -s
-hidden
-L/usr/local/lib'
@INC: /usr/local/lib/perl5/alpha-dec_osf/5.002 /usr/local/lib/perl5
/usr/local/lib/perl5/site_perl/alpha-dec_osf /usr/local/lib/per\
l5/site_perl .

####################### END OUTPUT OF 'perl -V'



And here is the output of myconfig:

####################### BEGIN OUTPUT OF 'myconfig'

Summary of my perl5 (revision 5.0 version 6 subversion 1)
configuration:
  Platform:
    osname=dec_osf, osvers=4.0, archname=alpha-dec_osf
    uname='osf1 ahnkenaten.adone.com v4.0 1229 alpha '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=define uselongdouble=undef
  Compiler:
    cc='cc', ccflags ='-std -fprm d -ieee -D_INTRINSICS
-I/usr/local/include -DLANGUAGE_C',
    optimize='-O4',
    cppflags='-std -ieee -D_INTRINSICS -I/usr/local/include
-DLANGUAGE_C'
    ccversion='V5.9-005', gccversion='', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='ld', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc
/usr/lib /var/shlib
    libs=-ldbm -ldb -lm -liconv -lutil
    perllibs=-lm -liconv -lutil
    libc=/usr/shlib/libc.so, so=so, useshrplib=true,
libperl=libperl.so
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='
-Wl,-rpath,/usr/users/paulm/perl5_6_1/lib/5.6.1/alpha-dec_osf/CORE'
    cccdlflags=' ', lddlflags='-shared -expect_unresolved "*" -O4
-msym
-std -s -L/usr/local/lib'


Any help would be much appreciated.


--Dave Storrs
dstorrs@dstorrs.com


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

Date: Tue, 10 Jul 2001 18:44:38 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: trying to install perl on Alpha
Message-Id: <q2I27.152575$v5.11537688@news1.rdc1.ct.home.com>

David Storrs <dstorrs@dstorrs.com> wrote:
> I've never tried to install perl from source before, and I'm not
> having
> much luck...I downloaded the source (stable.tar.gz), ran Configure,
> and
> tried to do the 'make', 'make test', 'make install'
> series.  Unfortunately, it bombs out on 'make', with the following
> output:

> Can't locate File/Glob.pm in @INC (@INC contains: ../../lib

Double-check to make sure File::Glob is in the list of modules
you told perl to build. It ought to be there by default, but
maybe something got eaten somewhere along the line. 

					Dan


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

Date: Mon, 9 Jul 2001 17:21:22 +0200
From: Oliver Sass <osass@ix.urz.uni-heidelberg.de>
Subject: turn off redirect in LWP?
Message-Id: <9ici5j$mo7$1@news.urz.uni-heidelberg.de>

Hallo everyone!
Does anybody know an easy method to turn off autmatic redirection for GET 
Requests with the LWP-Agent?
-Oliver
-- 
## Oliver
## sass@gw.sino.uni-heidelberg.de
## Heidelberg, Germany


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

Date: 9 Jul 2001 16:10:40 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: turn off redirect in LWP?
Message-Id: <slrn9kjlsm.5r4.rgarciasuarez@rafael.kazibao.net>

Oliver Sass wrote in comp.lang.perl.misc:
> Hallo everyone!
> Does anybody know an easy method to turn off autmatic redirection for GET 
> Requests with the LWP-Agent?

Looking through the man page for LWP::UserAgent gives two answers :

1. use simple_request() instead of request()

or

2. make a subclass of LWP::UserAgent that overrides redirect_ok().

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Mon, 09 Jul 2001 23:07:11 +0200
From: Philip Newton <pne-news-20010709@newton.digitalspace.net>
Subject: Re: variable require
Message-Id: <i27kktckqbnaq7nop6i0nu0t5sfc264nov@4ax.com>

[Groups trimmed to comp.lang.perl.misc]

On Mon, 9 Jul 2001 15:36:47 +0100, "jimbo" <jimbo@soundimages.co.uk>
wrote:

> require is compile time

Nope, it's not. Are you confusing it with 'use', maybe?

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Wed, 11 Jul 2001 07:43:51 +0200
From: "scotth" <scott@remove.generator.co.za>
Subject: Very good regex question?
Message-Id: <3b4be806$0$227@hades.is.co.za>

Hi All.
My regular expression knowledge is not the best, but can anyone tell how
this would be achieved?
I have a word which may have apostrophes ( ' ) surrounding it.
eg 'foobar'
I want to remove these using s/
s/\'//g will work BUT
in the case of a word such as
eg foobar's
I want to remove the 's and only be left with "foobar". and the above regex
would leave me with "foobars"
AND
In the case of a word which requires an apostrophe in the non possessive
context, such as
eg O'Hagan
I want to retain the apostrophe.
so...
I need a regex which will give me:
O'Foobar from 'O'Foobar'
and
foobar from 'foobar's'
I know this is possible, but how would I do it most efficiently?
Thanks in advance
Scott

--
Scott Houseman
Software Developer/Systems Administrator

tel  +27 21 425 9710
fax +27 21 425 9713

GENERATOR COMMUNICATIONS | BE AN ISLAND




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

Date: Wed, 11 Jul 2001 08:24:59 +0200
From: "scotth" <scott@remove.generator.co.za>
Subject: Re: Very good regex question?
Message-Id: <3b4bf1ab$0$231@hades.is.co.za>

Hi all.
Me again!
This seems to work for most scenarios.

#!/usr/bin/perl -w
$string = "\'test\'s\'";
print "$string\n";          # RETURNS "'test's'"
$string =~ s/^\'//g;     # REMOVE ' AT BEGINNING.
$string =~ s/\'$//g;     # REMOVE ' AT END.
$string =~ s/\'[\w]//g; # REMOVE ' AND SINGLE LETTER FOLLOWING IT.
print "$string\n";          # RETURNS "test"

"scotth" <scott@remove.generator.co.za> wrote in message
news:3b4be806$0$227@hades.is.co.za...
> Hi All.
> My regular expression knowledge is not the best, but can anyone tell how
> this would be achieved?
> I have a word which may have apostrophes ( ' ) surrounding it.
> eg 'foobar'
> I want to remove these using s/
> s/\'//g will work BUT
> in the case of a word such as
> eg foobar's
> I want to remove the 's and only be left with "foobar". and the above
regex
> would leave me with "foobars"
> AND
> In the case of a word which requires an apostrophe in the non possessive
> context, such as
> eg O'Hagan
> I want to retain the apostrophe.
> so...
> I need a regex which will give me:
> O'Foobar from 'O'Foobar'
> and
> foobar from 'foobar's'
> I know this is possible, but how would I do it most efficiently?
> Thanks in advance
> Scott
>
> --
> Scott Houseman
> Software Developer/Systems Administrator
>
> tel  +27 21 425 9710
> fax +27 21 425 9713
>
> GENERATOR COMMUNICATIONS | BE AN ISLAND
>
>




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

Date: Wed, 11 Jul 2001 16:09:31 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Very good regex question?
Message-Id: <7rS27.26$BZ3.1611@vic.nntp.telstra.net>

"scotth" <scott@remove.generator.co.za> wrote in message
news:3b4be806$0$227@hades.is.co.za...
> Hi All.
> My regular expression knowledge is not the best, but can anyone tell how
> this would be achieved?
> I have a word which may have apostrophes ( ' ) surrounding it.
> eg 'foobar'
> I want to remove these using s/
> s/\'//g will work BUT
> in the case of a word such as
> eg foobar's
> I want to remove the 's and only be left with "foobar". and the above
regex
> would leave me with "foobars"
> AND
> In the case of a word which requires an apostrophe in the non possessive
> context, such as
> eg O'Hagan
> I want to retain the apostrophe.
> so...
> I need a regex which will give me:
> O'Foobar from 'O'Foobar'
> and
> foobar from 'foobar's'
> I know this is possible, but how would I do it most efficiently?
> Thanks in advance
> Scott
>

I think this should work.  At least it does with the case you describe
above.
s/'([\w']+?[^s])'(s')?/$1/g;


Could have a problem with 'Foobars's' though.

Sometimes it is easier to deal with the steps one at a time, and there
really is no harm with using a couple of regexen in sequence to solve the
problem.

s/(^|\W)'(\w)/$1$2/g;
s/(\w)'(\W|$)/$1$2/g;
s/'s\b//g;

That sequence should cover all eventualities.



Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";








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

Date: Wed, 11 Jul 2001 16:13:28 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Very good regex question?
Message-Id: <PuS27.27$BZ3.1652@vic.nntp.telstra.net>

"scotth" <scott@remove.generator.co.za> wrote in message
news:3b4bf1ab$0$231@hades.is.co.za...
> Hi all.
> Me again!
> This seems to work for most scenarios.
>
> #!/usr/bin/perl -w
> $string = "\'test\'s\'";

Single quote does not need to be escaped in a double quote string.

> print "$string\n";          # RETURNS "'test's'"
> $string =~ s/^\'//g;     # REMOVE ' AT BEGINNING.

Single quote does not need to be escaped in the first half of a regex.  g
modifier is useless as there can only be 1 beginning of the string.

> $string =~ s/\'$//g;     # REMOVE ' AT END.

Ditto, only one end of string.

> $string =~ s/\'[\w]//g; # REMOVE ' AND SINGLE LETTER FOLLOWING IT.

\w alone does not need to be in a character class, (it does if combined with
other things).  This will also break on O'Foobar from your other example.

> print "$string\n";          # RETURNS "test"
>

See my other post.

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
$d='$_$a$s$b$w';$e='$_$a$s$b';sub d{$h=shift;$h=~s/\$(\w+)/${$1}/g;return$h}
sub
e{return(shift!=1)?'s':''}for(reverse(1..100)){$s=e($_);$f=d($d);$g=d($e);
$c.="$f\n$g\n$t\n";$_--;$s=e($_);$e=d($d);$c.="$e\n\n";}print"$c*hic*";




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

Date: Mon, 09 Jul 2001 15:50:44 GMT
From: "R. Eranki" <pr_NOSPAM_lx@m*NOSPAM*ac.com>
Subject: Re: What is the best way to get the size of file
Message-Id: <090720011151552635%pr_NOSPAM_lx@m*NOSPAM*ac.com>

In article <3B498B3E.3F07C471@firmanet.is>, Tryggvi Farestveit
<tryggvi@firmanet.is> wrote:

> Hi,
> 
> I have gone thru FAQ but didn't find any information about this.
> 
> What I need is to get filesize of some file. For example "/etc/passwd".
> 
> - Tryggvi Farestveit

You could do something like

$filesize = -s "/path/to/file";

or use the stat("/path/to/file") command to access file stats (is it
element 8 of the returned array?)


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

Date: 09 Jul 2001 18:03:18 +0100
From: nobull@mail.com
Subject: Re: What is the best way to get the size of file
Message-Id: <u9elrq9grt.fsf@wcl-l.bham.ac.uk>

Tryggvi Farestveit <tryggvi@firmanet.is> writes:

> I have gone thru FAQ but didn't find any information about this.

FAQs are _not_ intended to replace the manuals.

> What I need is to get filesize of some file.

Other's have given you a fish so you you can eat for today.  However I
think it would be of more real help to you to give you a fishing
lesson...

You can reasonably guess there's likely be a builtin Perl function to
do this.  So look in the vacinity of occurances of the word "size" in
the "perlfunc" manual.

I found 23 occurances, the second occurance was in the description of
the -s operator that returns the size of a file.

Note: you could have looked for "file" but that matches 220 times and
the function you sought is about the 14th match.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Mon, 09 Jul 2001 22:47:11 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: What is the best way to get the size of file
Message-Id: <3B4A3470.5588C74B@acm.org>

> John Imrie wrote:
> 
> my $file_size = -s "filename';
                     ^        ^

> would be quicker
                   way to get a syntax error.


John
-- 
use Perl;
program
fulfillment


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

Date: Mon, 09 Jul 2001 11:37:36 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Why 1st line always mising.
Message-Id: <3B49CFC0.84D9C4D6@earthlink.net>

Terence wrote:
> 
> I'm trying to read an input file and output to another file.
> But the information for the 1st record is always missing.
> Why is this so?
> 
> while{(INFILE>){

Assuming you meant while(<INFILE>) { here, this loops through all the
lines of the file, putting the line in $_ for the duration of the block.

>     read(INFILE, $coname, 40);
>     read(INFILE, $fname, 40, 15);
>     read(INFILE, $lname, 40, 40);
>     read(INFILE, $email, 40, 40);
>     read(INFILE, $uid, 20, 40);

These read *more* data from INFILE, looking at whatever's in the file
following the most recently read $_ thingy.

What you probably want is something like:
	my ($coname, $fname, $lname, $email, $uid) =
		unpack 'A40 A40 A40 A40 A20", $_;
I'm guessing on the field sizes.

>    print OUTFILE "$coname\n"

If you only want one of those values, you could use:
	my $coname = substr $_, 0, 40;

> }

Also, since your file uses fixed size records, you may get better
results if you locally set $/ to a reference to the record size:
	local $/ = \180;
Before the while loop, of course.

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: 09 Jul 2001 18:00:05 +0100
From: nobull@mail.com
Subject: Re: Why does this hash work? %h->{a}='v'
Message-Id: <u9ith29gx6.fsf@wcl-l.bham.ac.uk>

demerphq@hotmail.com (Yves Orton) writes:

>        %hash->{other_attrib}=$other_value;
> 
> would be totally incorrect.  Except it isn't!! The previous seems to
> work just fine.  Any ideas of why?

It's a well known and long standing bug that is discussed here (and in
p5p IIRC) every few months.

For example, just like you, I idependantly discovered a manifestation
of this bug and posted it here with the subject "LHS of -> can be
array or hash - since when?" on 16th March 2000.

I've seen it a number of times since.

Jeff Pinyan apparently even raised this issue at YAPC 1999.
 
Despite all that I cannot find an official ID for this bug on
bugs.perl.org.

Does anyone know the ID of this bug or it it really not in the
database?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Mon, 09 Jul 2001 18:18:28 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Why does this hash work? %h->{a}='v'
Message-Id: <3b49f573.4f0$37a@news.op.net>

In article <u9ith29gx6.fsf@wcl-l.bham.ac.uk>,  <nobull@mail.com> wrote:
>Does anyone know the ID of this bug or it it really not in the
>database?

Perhaps nobody has reported it as a bug because (a) it is harmless,
and (b) 'fixing' it owuld break a lot of existing code.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 1281
***************************************


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