[27898] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9262 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 8 11:15:32 2006

Date: Thu, 8 Jun 2006 08:15:25 -0700 (PDT)
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, 8 Jun 2006     Volume: 10 Number: 9262

Today's topics:
        Inserting lines into text files, or howto "fix" vCards  analogquack@gmail.com
    Re: Inserting lines into text files, or howto "fix" vCa analogquack@gmail.com
    Re: Inserting lines into text files, or howto "fix" vCa analogquack@gmail.com
    Re: Inserting lines into text files, or howto "fix" vCa <DJStunks@gmail.com>
    Re: Inserting lines into text files, or howto "fix" vCa <benmorrow@tiscali.co.uk>
    Re: Inserting lines into text files, or howto "fix" vCa <noreply@gunnar.cc>
    Re: Inserting lines into text files, or howto "fix" vCa <noreply@gunnar.cc>
    Re: Inserting lines into text files, or howto "fix" vCa <someone@example.com>
        m///x and slashes in comments: bug or feature? <ro.naldfi.scher@gmail.com>
    Re: m///x and slashes in comments: bug or feature? <peace.is.our.profession@gmx.de>
    Re: m///x and slashes in comments: bug or feature? <mol10metal@hotmail.com>
    Re: m///x and slashes in comments: bug or feature? <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: m///x and slashes in comments: bug or feature? <benmorrow@tiscali.co.uk>
    Re: m///x and slashes in comments: bug or feature? <peace.is.our.profession@gmx.de>
    Re: m///x and slashes in comments: bug or feature? <benmorrow@tiscali.co.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 6 Jun 2006 17:25:54 -0700
From: analogquack@gmail.com
Subject: Inserting lines into text files, or howto "fix" vCards having no n: entry
Message-Id: <1149639954.795624.121730@f6g2000cwb.googlegroups.com>

I am needing to copy a line of text within a text file and insert a
slightly modified version of that line at a different point in same
file. I have had difficulty finding any text I can grok which would
assist me in this matter.

If you don't care about the details of my specific project, any general
example would be very helpful and gratefully accepted. If you do care
about the details (or if it helps someone else who is trying to perform
the same task) the specifics of my challenge and the script I am
working with follow.

The goal is to add N: and FN: entries into vCards having none by
copying the data from the ORG: line. In English, some contacts have
company names but no first and last name, which are represented on the
N: and FN: lines. Some address book apps expect to have a line in the
N: or FN: fields (Outlook for example) while others don't care (Palm
Desktop for example).

To be specific, the text files look like this:

BEGIN:VCARD
VERSION:2.1
N:LastName;FirstName
FN:FirstName LastName
TITLE:Title
ORG:Company
ADR;WORK:;;WorkAddress;WorkCity;WorkState;WorkZip;WorkCountry
URL;WORK:Website
TEL;WORK:Work#

When there is no N: or FN: fields, they would look like so:

BEGIN:VCARD
VERSION:2.1
TITLE:Title
ORG:Company
ADR;WORK:;;WorkAddress;WorkCity;WorkState;WorkZip;WorkCountry
URL;WORK:Website
TEL;WORK:Work#

I need to copy the ORG: line, "ORG:Company" in this example, and have
it inserted just below the VERSION:2.1 line like so:

BEGIN:VCARD
VERSION:2.1
N:Company
FN:Company
TITLE:Title
ORG:Company
ADR;WORK:;;WorkAddress;WorkCity;WorkState;WorkZip;WorkCountry
URL;WORK:Website
TEL;WORK:Work#

I would like to integrate this into a Perl script I have found in a
prior thread which works well except for this one lacking feature. The
script parses a single Palm Desktop-exported vCard file having multiple
contacts within it and output separate vCard files, one for each
contact. If I could integrate the two functions I would be able to
transform my thousand or so contacts in one fell swoop into files that
can be imported into Outlook. =)

Here is the script as I am currently using it:

#!/usr/bin/perl -w
use strict;
# vcard 2.1 - rfc2425,rfc2426

my $pathname       = 'C:/No_Install/_Analog/Office/Output';
my $sourcefilename = '../Palm.vcf';

$/ = ''; # set paragraph mode
open SOURCE, "< $pathname/$sourcefilename"
    or die "Couldn't open $sourcefilename for reading: $!";
while ( <SOURCE> ) {
    chomp;
    my $sinkfilename;
    if ( /^(fn[;:].+)/im ) {
        ( undef, $sinkfilename ) = split /(?<!\\):/, $1, 2;
        }
    elsif ( /^(n[;:].+)/im ) {
        ( undef, $sinkfilename ) = split /(?<!\\):/, $1, 2;
        # n: field is "lastname;firstname"
        # change to "firstname lastname"
        $sinkfilename = join ' ', reverse split /(?<!\\);/,
$sinkfilename;
        }
    $sinkfilename =~ s/[^\w~,\- ]//g;
    my $count = '';
    if ( -e "$pathname/$sinkfilename" ) {
        1 while -e "$pathname/" . ++$count . "$sinkfilename" . ".vcf";
        }
    $sinkfilename .= ".vcf" ;
    open SINK, "> $pathname/$count$sinkfilename"
        or die "Couldn't open $count$sinkfilename for writing: $!";
    print SINK "$_\n" or die "can't write $count$sinkfilename: $!";
    close SINK or die "couldn't close $count$sinkfilename: $!";
    }
close SOURCE or die "couldn't close $sourcefilename: $!";

__END__


You can see the thread I gaffed this from here for reference:
http://groups.google.com/group/comp.lang.perl.misc/browse_thread/thread/d476fa37427ed15f/79e269b866d12028?lnk=st&q=split+palm+vcard&rnum=1#79e269b866d12028



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

Date: 6 Jun 2006 18:51:00 -0700
From: analogquack@gmail.com
Subject: Re: Inserting lines into text files, or howto "fix" vCards having no n: entry
Message-Id: <1149645060.925101.224580@g10g2000cwb.googlegroups.com>

Thank you. Your clue results in a helpful pointer to the Tie::File
module.

It will take me quite a bit to figure out the rest of the puzzle. If
anyone else has any clues regarding how I might use the Tie::File
module to accomplish this task, I'd appreciate it.

Please understand that I am a Perl novice and the following is the best
I can do to describe where I'm trying to go with this. I've got to use
some plain English pseudocode where I've got no idea how to write the
Perl stuff in order to convey myself. I imaging it would be something
like (assuming this processing is done before the vCard file is split
into multiple vCards):

use Tie::File

tie @array, 'Tie::File', $sourcefilename or die;

for (@array) {
   If, in a given paragraph there are no lines beginning with "N:" or
"FN:" then {
      $org = the line of this paragraph beginning with "ORG:"
      $n = $org except we've replaced "ORG" with "N"
      $fn = $org except we've replaced "ORG" with "FN"
      Insert $n and $fn as two new lines just after the line of this
paragraph which begins with "VERSION:2.1"
   }
}

How would I go about completing the "for" statement in proper Perl?

I'm providing an example vCard to complete the illustration, with the
first record (paragraph) being a record which should be ignored,
followed by three that should have "N:" and "FN:" lines inserted into
them:

BEGIN:VCARD
VERSION:2.1
N:LastName;FirstName
FN:FirstName LastName
TITLE:Title
ORG:Company
ADR;WORK:;;WorkAddress;WorkCity;WorkState;WorkZip;WorkCountry

BEGIN:VCARD
VERSION:2.1
ORG:1 Day Paint and Body
ADR;WORK:;;27592 Camino Capistrano;Laguna Niguel;CA
NOTE:7:30am-6pm Mon-Fri
TEL;WORK:(949) 582-1821
X-Palm-Custom1:http://www.1daypaint.com/
END:VCARD

BEGIN:VCARD
VERSION:2.1
ORG:2 Advanced Studios
ADR;WORK:;;65 Enterprise;Aliso Viejo;CA;92656
TEL;WORK:949.443.2112
TEL;FAX:949.330.7581
EMAIL:info@2advanced.com
X-Palm-Custom1:http://www.2advanced.com/
END:VCARD

BEGIN:VCARD
VERSION:2.1
ORG:604 List
X-Palm-Custom1:www.party.net
END:VCARD



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

Date: 7 Jun 2006 10:42:47 -0700
From: analogquack@gmail.com
Subject: Re: Inserting lines into text files, or howto "fix" vCards having no n: entry
Message-Id: <1149702167.225141.33080@y43g2000cwc.googlegroups.com>

Woah!

John,

I envy your skills and am grateful for your contribution. I'll let you
know how this works out for me.

I'll also do my best to learn the logic of your parsing and the syntax
of your regex so as to be able to better formulate my questions in the
future. =3D)

Gunnar,

While I respectfully understand your stance of  "you need to do some
Perl literacy work", I'll note here I have already read two complete
O'Reilly books on Perl and I still struggle to understand it. The
language itself is truly obfuscated on its own. but regex of any flavor
has really never been easy to work out as a beginner for any task
beyond the most simple pattern matching. (At least that would be the
typical experience as conveyed to me by most humans I interact with,
though I know many people seem to have natural knack for such things.)

The point of this being to say that I feel community forums such as
Usenet are the appropriate place to learn the more difficult aspects of
any language. Also it should be said that I already have done the RTFM
type work on my end but apparently am just too thick-skulled to grok
this stuff without a little hand-holding.

That being said, I appreciate your tolerance of my my newbie naivet=E9
and the link to http://learn.perl.org/ . I'll review the material
there. Thanks for the tip. ;)



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

Date: 7 Jun 2006 11:28:13 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: Inserting lines into text files, or howto "fix" vCards having no n: entry
Message-Id: <1149704893.164010.154080@j55g2000cwa.googlegroups.com>


John W. Krahn wrote:
> analogquack@gmail.com wrote:
> > I would like to integrate this into a Perl script I have found in a
> > prior thread which works well except for this one lacking feature. The
> > script parses a single Palm Desktop-exported vCard file having multiple
> > contacts within it and output separate vCard files, one for each
> > contact. If I could integrate the two functions I would be able to
> > transform my thousand or so contacts in one fell swoop into files that
> > can be imported into Outlook. =)
> >
> > Here is the script as I am currently using it:
>
> Since I posted the script you are borrowing I might as well post this update
> as well.  :-)   I did some testing so hopefully this will work correctly.

'borrowing' would indicate it's going to be returned afterward, right?
:P

anyhow, just thought I'd mention that there's quite a few modules on
CPAN for parsing vFiles, and getting and setting vCard (and vCalendar)
attributes in an OO way...

y'all might want to check-ch-check-check-check-ch-check it out.

-jp



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

Date: Wed, 7 Jun 2006 21:59:28 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Inserting lines into text files, or howto "fix" vCards having no n: entry
Message-Id: <garjl3-74g.ln1@osiris.mauzo.dyndns.org>


Quoth analogquack@gmail.com:
> While I respectfully understand your stance of  "you need to do some
> Perl literacy work", I'll note here I have already read two complete
> O'Reilly books on Perl and I still struggle to understand it.

Which two? I would recommend starting with 'Learning Perl' by Randal
Schwartz, moving on to the Camel Book ('Programming Perl', by Larry Wall
et al.). If those are the two, then you perhaps need to read them again,
more carefully. In particular, if you are learning programming, as
opposed to simply learning Perl, then you must expect it to take a lot
of work. THe concepts involved are not easy.

> The language itself is truly obfuscated on its own.

Oi! :)
I wouldn't recommend saying that around here, especially from your
position as someone who doesn't understand Perl yet. From my POV,
(well-written) Perl is one of the clearest languages I've used, and the
most like English in feel (as opposed to the COBOL/SQL/AppleScript-type
languages, which look like English but don't feel like it). If, when you
have a decent grasp of the language, you still feel this, then I would
suggest using something else. This is not meant to put you off using
Perl, or to be disparaging(sp?): different people have different tastes,
and you'll probably be happier writing in a language which fits yours.

> but regex of any flavor has really never been easy to work out as a
> beginner for any task beyond the most simple pattern matching. (At
> least that would be the typical experience as conveyed to me by most
> humans I interact with, though I know many people seem to have natural
> knack for such things.)

This is certainly true, and the remedy for it is practice. In the
meanwhile, don't be ashamed to use simpler solutions you understand
better. Certainly make heavy use of the /x switch and comments in your
regexes: they will help you understand them later. And don't be put off
if people here say things like 'don't use index for that, use a regex:
it's more Perlish': they are (mostly) honestly trying to help you use
the language as designed. As a rule, if you've read their code and made
a good effort to understand it from the docs (which can be a little
tricky to understand themselves, at times, I know), and you provide
evidence of this, people will be willing to explain things further until
you do understand them.

Ben

-- 
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces mollit animos, tristesque mentes erigit.| benmorrow@tiscali.co.uk
Musica vel ipsas arbores et horridas movet feras.     |


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

Date: Wed, 07 Jun 2006 02:33:37 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Inserting lines into text files, or howto "fix" vCards having no n: entry
Message-Id: <4eml72F1fk63kU1@individual.net>

analogquack@gmail.com wrote:
> I am needing to copy a line of text within a text file and insert a
> slightly modified version of that line at a different point in same
> file.

     perldoc -q "insert a line"

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Wed, 07 Jun 2006 07:29:02 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Inserting lines into text files, or howto "fix" vCards having no n: entry
Message-Id: <4en6h0F1ffgilU1@individual.net>

analogquack@gmail.com wrote:
> Please understand that I am a Perl novice and the following is the best
> I can do to describe where I'm trying to go with this.

<snip>

> use Tie::File
> 
> tie @array, 'Tie::File', $sourcefilename or die;
> 
> for (@array) {
>    If, in a given paragraph there are no lines beginning with "N:" or
> "FN:" then {
>       $org = the line of this paragraph beginning with "ORG:"
>       $n = $org except we've replaced "ORG" with "N"
>       $fn = $org except we've replaced "ORG" with "FN"
>       Insert $n and $fn as two new lines just after the line of this
> paragraph which begins with "VERSION:2.1"
>    }
> }

Then you are not ready for the task. If you want to learn Perl, check 
out http://learn.perl.org/

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Wed, 07 Jun 2006 12:29:40 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Inserting lines into text files, or howto "fix" vCards having no n: entry
Message-Id: <UEzhg.21074$I61.17299@clgrps13>

analogquack@gmail.com wrote:
> I am needing to copy a line of text within a text file and insert a
> slightly modified version of that line at a different point in same
> file. I have had difficulty finding any text I can grok which would
> assist me in this matter.
> 
> If you don't care about the details of my specific project, any general
> example would be very helpful and gratefully accepted. If you do care
> about the details (or if it helps someone else who is trying to perform
> the same task) the specifics of my challenge and the script I am
> working with follow.
> 
> The goal is to add N: and FN: entries into vCards having none by
> copying the data from the ORG: line. In English, some contacts have
> company names but no first and last name, which are represented on the
> N: and FN: lines. Some address book apps expect to have a line in the
> N: or FN: fields

That is probably because according to http://www.imc.org/pdi/vcard-21.rtf the
N field is REQUIRED.

> (Outlook for example) while others don't care (Palm
> Desktop for example).
> 
> [snip]
> 
> I would like to integrate this into a Perl script I have found in a
> prior thread which works well except for this one lacking feature. The
> script parses a single Palm Desktop-exported vCard file having multiple
> contacts within it and output separate vCard files, one for each
> contact. If I could integrate the two functions I would be able to
> transform my thousand or so contacts in one fell swoop into files that
> can be imported into Outlook. =)
> 
> Here is the script as I am currently using it:

Since I posted the script you are borrowing I might as well post this update
as well.  :-)   I did some testing so hopefully this will work correctly.

#!/usr/bin/perl
use warnings;
use strict;

my $pathname       = 'C:/No_Install/_Analog/Office/Output';
my $sourcefilename = '../Palm.vcf';

$/ = ''; # set paragraph mode

open SOURCE, '<', "$pathname/$sourcefilename"
    or die "Cannot open '$sourcefilename' $!";

while ( <SOURCE> ) {
    chomp;

    my $fn;
    if ( /^(fn[;:].+)/im ) {
        $fn = ( split /(?<!\\):/, $1, 2 )[ 1 ];
        }

    my $n;
    if ( /^(n[;:].+)/im ) {
        $n = ( split /(?<!\\):/, $1, 2 )[ 1 ];
        # n: field is "lastname;firstname"
        # change to "firstname lastname"
        $n = join ' ', reverse split /(?<!\\);/, $n;
        }

    my $org;
    if ( !$fn && !$n && /^(org[;:].+)/im ) {
        $org = ( split /(?<!\\):/, $1, 2 )[ 1 ];
        $fn = $n = $org;
        s/(^version:.*\n)/$1N:$n\nFN:$fn\n/im;
        }

    ( my $sinkfilename = $n || $fn || $org ) =~ s/[^\w~,\- ]+//g;
    my $count = '';
    if ( -e "$pathname/$sinkfilename.vcf" ) {
        1 while -e "$pathname/" . ++$count . "$sinkfilename.vcf";
        }
    $sinkfilename = "$count$sinkfilename.vcf";

    open SINK, '>', "$pathname/$sinkfilename"
        or die "Cannot open '$sinkfilename' $!";
    print SINK "$_\n"
        or die "Cannot write '$sinkfilename' $!";
    close SINK
        or die "Cannot close '$sinkfilename' $!";
    }

close SOURCE or die "Cannot close '$sourcefilename' $!";

__END__



John
-- 
use Perl;
program
fulfillment


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

Date: 7 Jun 2006 05:49:17 -0700
From: "Ronny" <ro.naldfi.scher@gmail.com>
Subject: m///x and slashes in comments: bug or feature?
Message-Id: <1149684557.797093.99020@g10g2000cwb.googlegroups.com>

My perl is 5.8.3, and when I execute the following program:

#!/usr/local/bin/perl -ws
use strict;
"dummy" =~ /
   first|
   second| # this comment has a/slash
   third
/x;

I get the error message:

Bareword found where operator expected at ./matcherr.pl line 5, near
"second| # this comment has a/slash"
  (Might be a runaway multi-line // string starting on line 3)


The reason is the '/' in the comment. If I change the line to:

   second| # this comment has no slash

the program runs fine. This surprises me, because as I have understood
the
'x' modifier, a comment within the pattern should eat up everything
until the
end of the line. Seemingly, parsing for the terminating "/" happens
BEFORE
white space inside the pattern is removed. Or did I misunderstand
something
here?

Ronald



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

Date: Wed, 07 Jun 2006 14:57:01 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: m///x and slashes in comments: bug or feature?
Message-Id: <e66ilg$lta$1@mlucom4.urz.uni-halle.de>

Thus spoke Ronny (on 2006-06-07 14:49):

> #!/usr/local/bin/perl -ws
> use strict;
> "dummy" =~ /
>    first|
>    second| # this comment has a/slash
>    third
> /x;
> ...
> The reason is the '/' in the comment. If I change the line to:

How would the parser know what you intended here?
 "dummy" =~ /
    first|
   second| # this comment has a/s

would be "valid" also.

You have to make sure to give
some impression to the parser
in what you want ;-)

"dummy" =~ {
             first|
            second| # this comment has a/slash
             third
            }x;

Regards

Mirco


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

Date: 7 Jun 2006 06:39:28 -0700
From: "Nick of course" <mol10metal@hotmail.com>
Subject: Re: m///x and slashes in comments: bug or feature?
Message-Id: <1149687568.502968.23660@g10g2000cwb.googlegroups.com>


Ronny wrote:
> My perl is 5.8.3, and when I execute the following program:
>
> #!/usr/local/bin/perl -ws
> use strict;
> "dummy" =~ /
>    first|
>    second| # this comment has a/slash
>    third
> /x;
>
> I get the error message:
>
> Bareword found where operator expected at ./matcherr.pl line 5, near
> "second| # this comment has a/slash"
>   (Might be a runaway multi-line // string starting on line 3)
>
>
> The reason is the '/' in the comment. If I change the line to:
>
>    second| # this comment has no slash
>
> the program runs fine. This surprises me, because as I have understood
> the
> 'x' modifier, a comment within the pattern should eat up everything
> until the
> end of the line. Seemingly, parsing for the terminating "/" happens
> BEFORE
> white space inside the pattern is removed. Or did I misunderstand
> something
> here?
>
> Ronald

It's a parsing precedence problem.  The regex parser is looking for a /
to terminate the pattern - before it has parsed the /x.  So it does not
know until it has parsed the whole regex how to treat to how to treat
the #... comment syntax.  It does that in the next pass.



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

Date: Wed, 07 Jun 2006 15:10:21 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: m///x and slashes in comments: bug or feature?
Message-Id: <x%Bhg.10141$921.8529@newsread4.news.pas.earthlink.net>

Mirco Wahab wrote:
> [...]
> You have to make sure to give
> some impression to the parser
> in what you want ;-)
> 
> "dummy" =~ {
>              first|
>             second| # this comment has a/slash
>              third
>             }x;
> 
> Regards
> 
> Mirco

So you can use an anonymous hash to match an RE?

:)



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

Date: Wed, 7 Jun 2006 16:05:01 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: m///x and slashes in comments: bug or feature?
Message-Id: <th6jl3-76d.ln1@osiris.mauzo.dyndns.org>


Quoth "Nick of course" <mol10metal@hotmail.com>:
> 
> Ronny wrote:
> > My perl is 5.8.3, and when I execute the following program:
> >
> > #!/usr/local/bin/perl -ws
> > use strict;
> > "dummy" =~ /
> >    first|
> >    second| # this comment has a/slash
> >    third
> > /x;
> >
> > I get the error message:
> >
> > Bareword found where operator expected at ./matcherr.pl line 5, near
> > "second| # this comment has a/slash"
> >   (Might be a runaway multi-line // string starting on line 3)
> >
> >
> > The reason is the '/' in the comment. If I change the line to:
<snip>
> It's a parsing precedence problem.  The regex parser is looking for a /
> to terminate the pattern - before it has parsed the /x.  So it does not
> know until it has parsed the whole regex how to treat to how to treat
> the #... comment syntax.  It does that in the next pass.

 ...which is why perl6 puts the modifiers first.

Ben

-- 
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
                                                        benmorrow@tiscali.co.uk


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

Date: Wed, 07 Jun 2006 17:34:10 +0200
From: Mirco Wahab <peace.is.our.profession@gmx.de>
Subject: Re: m///x and slashes in comments: bug or feature?
Message-Id: <e66rs5$oen$1@mlucom4.urz.uni-halle.de>

Thus spoke Mumia W. (on 2006-06-07 17:10):

> Mirco Wahab wrote:
>> "dummy" =~ {
>>              first|
>>             second| # this comment has a/slash
>>              third
>>             }x;
> 
> So you can use an anonymous hash to match an RE?

Thanks for pointing out this stupid mistake
(didn't sleep very long last night ;-)

Of course, this must be a quoted regex
then, either:

 my $rg = qr{
           first|
          second|  # this comment has a/slash
           third
          }x;
 "dummy" =~ $rg  and print 1;


or:

 "dummy" =~ qr{
           first|
          second|  # this comment has a/slash
           third
          }x and print 1;



Thanks and sorry (what did I mesh up this time ;-)

Mirco


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

Date: Wed, 7 Jun 2006 17:11:33 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: m///x and slashes in comments: bug or feature?
Message-Id: <leajl3-j2e.ln1@osiris.mauzo.dyndns.org>


Quoth Mirco Wahab <peace.is.our.profession@gmx.de>:
> Thus spoke Mumia W. (on 2006-06-07 17:10):
> > Mirco Wahab wrote:
> >> "dummy" =~ {
> >>              first|
> >>             second| # this comment has a/slash
> >>              third
> >>             }x;
> > 
> > So you can use an anonymous hash to match an RE?
> 
>  "dummy" =~ qr{
>            first|
>           second|  # this comment has a/slash
>            third
>           }x and print 1;

You don't need to use qr//, you can just use m//:

"dummy" =~ m{...}x and print 1;

Ben

-- 
Every twenty-four hours about 34k children die from the effects of poverty.
Meanwhile, the latest estimate is that 2800 people died on 9/11, so it's like
that image, that ghastly, grey-billowing, double-barrelled fall, repeated
twelve times every day. Full of children. [Iain Banks]  benmorrow@tiscali.co.uk


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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