[33045] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4321 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 3 03:09:18 2014

Date: Wed, 3 Dec 2014 00:09:03 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 3 Dec 2014     Volume: 11 Number: 4321

Today's topics:
    Re: Help needed on Regular Expressions <ben.usenet@bsb.me.uk>
    Re: How to write an open(GLOB, ...) wrapper? <whynot@pozharski.name>
    Re: How to write an open(GLOB, ...) wrapper? <rweikusat@mobileactivedefense.com>
    Re: How to write an open(GLOB, ...) wrapper? <rweikusat@mobileactivedefense.com>
    Re: Need to strip off the non wordy characters <rweikusat@mobileactivedefense.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 02 Dec 2014 14:20:21 +0000
From: Ben Bacarisse <ben.usenet@bsb.me.uk>
Subject: Re: Help needed on Regular Expressions
Message-Id: <87a936jfq2.fsf@bsb.me.uk>

clearguy02@yahoo.com writes:
<snip>
> The below snippet is not working.. where am I doing wrong??

The main problem is that the lines you read retain the terminator.  Add
a chomp $1 and remove the \n from the print and you will have pretty
much what you want.  You should also ensure that the match is at the
start of a line, but that's a detail that will probably never cause a
problem.

> use strict;
> use warnings;
>
> open F1, "output.txt" or die $!;
> open F2, "AllProjects.txt" or die $!;
>
> my @file1 = <F1>;
> my @file2 = <F2>;
>
> my $i;
> my $j;
>
> for $i (@file1)
>   { 
chomp $i;
>     for $j (@file2)
>      { 
>        if ($j =~ /\Q$i/) 
/$\Q$i/
>          { 
>            print "$j\n"; 
print $j;
>          } 
>      } 
>   }                         
>
> close(F1);
> close(F2);

I would probably have written:

  my $alts = join("|", map {chomp $_; "\Q$_"} <F1>);
  while (<F2>) {
      print if /^($alts)/;
  }


-- 
Ben.


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

Date: Tue, 02 Dec 2014 09:37:52 +0200
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: How to write an open(GLOB, ...) wrapper?
Message-Id: <slrnm7qr2g.89p.whynot@orphan.zombinet>

with <hbf.20141201gppz@bombur.uio.no> Hallvard Breien Furuseth wrote:
> Eric Pozharski writes:
>> with <hbf.20141128kpjv@bombur.uio.no> Hallvard Breien Furuseth wrote:

>>> I know the program should have been using $filehandles instead
>>> of GLOBs, but such a rewrite would not be amusing at this time.
>> I think you have a slight bit of misunderstanding.  In Perl filehandles
>> are called GLOBs:
> Just a problem with terminology.  I'm talking about the programming
> style:  open(HANDLE...) vs open($my variable...).

Exactly.  Global variables vs. lexical variables is programming style.
All caps variable names have no special meaning for perl (with slight
strict-related quirk).  With dreaded utf8.pm you can do even crazier
things.

>> (I'm pulling out this gun for the first time.)  What is you're trying to
>> do?
> I have a program doing open(FOO, "<", $filename).  I want to replace
> the open() calls to myopen() which does more stuff, without changing
> the rest of the program (yet) to use $variable-style filehandles.

Well, GLOBs are still variables (they just have no sigil for historic
reasons).  If your program doesn't open-or-die then there's autodie.pm
(never used it myself).  I'm not arguing you out of this just because I
don't understand what you can do with myopen() -- you're free to do
whatever you want.  You just achieve nothing.

*CUT*

-- 
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom


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

Date: Tue, 02 Dec 2014 13:00:40 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: How to write an open(GLOB, ...) wrapper?
Message-Id: <87388yjjev.fsf@doppelsaurus.mobileactivedefense.com>

Eric Pozharski <whynot@pozharski.name> writes:
> with <hbf.20141201gppz@bombur.uio.no> Hallvard Breien Furuseth wrote:

[...]

>> I have a program doing open(FOO, "<", $filename).  I want to replace
>> the open() calls to myopen() which does more stuff, without changing
>> the rest of the program (yet) to use $variable-style filehandles.
>
> Well, GLOBs are still variables (they just have no sigil for historic
> reasons).

Objects have sigils which enable the same name (that's something without
a sigil) to refer to objects of different types and the 'glob sigil' is
*,

[rw@doppelsaurus]~#perl -e 'print(\@dodo, "\n", \*dodo, "\n")'
ARRAY(0x6234a0)
GLOB(0x623488)

As already written yesterday, globs are usually used as symbol table
entries which means they're associated with some name which is a key in
the 'symbol' hash table of a package. For historical reasons, functions/
subroutines/ operators accept a bareword (or a string) as 'I/O handle
argument' and then use the I/O-handle associated with the glob the
passed name (bareword or not) maps to,

[rw@doppelsaurus]~#perl -e 'open("Loetzinn", "<", "/etc/passwd"); $in = <Loetzinn>; print($in);'
root:x:0:0:root:/root:/bin/bash


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

Date: Tue, 02 Dec 2014 13:18:40 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: How to write an open(GLOB, ...) wrapper?
Message-Id: <87y4qqi40f.fsf@doppelsaurus.mobileactivedefense.com>

Hallvard Breien Furuseth <h.b.furuseth@usit.uio.no> writes:
> Eric Pozharski writes:
>> with <hbf.20141128kpjv@bombur.uio.no> Hallvard Breien Furuseth wrote:
>>
>>> I know the program should have been using $filehandles instead
>>> of GLOBs, but such a rewrite would not be amusing at this time.
>>
>> I think you have a slight bit of misunderstanding.  In Perl filehandles
>> are called GLOBs:
>
> Just a problem with terminology.  I'm talking about the programming
> style:  open(HANDLE...) vs open($my variable...).

The first passes a glob name as bareword and will use the I/O handle
slot of the glob named HANDLE for the actual I/O handle. The second
(presumably) uses a scalar with undefined value instead (any will do,
ie, including the my in this way is not necessary). perl then creates an
anonymous glob (not associated with a name which is a key in some symbol
table), assigns a reference to that to the scalar and uses the I/O
handle slot of this glob.

>> (I'm pulling out this gun for the first time.)  What is you're trying to
>> do?
>
> I have a program doing open(FOO, "<", $filename).  I want to replace
> the open() calls to myopen() which does more stuff, without changing
> the rest of the program (yet) to use $variable-style filehandles.

If you're compiling without strict, any subroutine will work. With
strict, you'll need to use a suitable prototype, eg

---------
use strict;

sub myopen(*@)
{
    no strict 'refs';
    open($_[0], @_[1 .. $#_]) or die("$!");
}

myopen(ORC, '<', '/etc/passwd');

my $in = <ORC>;

print($in);

my $fh;

myopen($fh, '<', '/etc/passwd');

$in = <$fh>;

print($in);
---------

The * (in the prototype) is necessary to allow using a bareword to name
a glob, the 'no strict refs' allows use of the bareword name to refer to
a glob (a symbolic reference).


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

Date: Tue, 02 Dec 2014 15:41:09 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Need to strip off the non wordy characters
Message-Id: <87zjb6rre2.fsf@doppelsaurus.mobileactivedefense.com>

clearguy02@yahoo.com writes:
> I have the following data:
>
> ++++++++++++++
> 411 Availability 79 0%
> [SITESPEED]­SRP 1 0%
> Accessibility Evaluator 53 0%
> Accounting Access Provisioning 6 0%
> Activities Stream 1 0%
> Adverb Funnel Reporting 14 0%
> Adverb Performance Tracking Data Mart 27 65%
> Channeling 53 0%
> AE ­ Attribute Extraction 113 50%
> +++++++++++++++++
>
> Now I want the output to be as follows (Only Ad Name with no numbers and no percentages at the end of the Ad name):
>
> ++++++++++
> 411 Availability
> [SITESPEED]­SRP
> Accessibility Evaluator
> Accounting Access Provisioning
> Activities Stream
> Adverb Funnel Reporting
> Adverb Performance Tracking Data Mart
> Channeling
> AE ­ Attribute Extraction
> +++++++++++++

perl -lpe 's/[^A-Za-z]+$//'

NB: This won't work with "weird IBM encodings".


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 4321
***************************************


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