[31725] in Perl-Users-Digest
Perl-Users Digest, Issue: 2988 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 13 11:09:40 2010
Date: Sun, 13 Jun 2010 08:09:09 -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 Sun, 13 Jun 2010 Volume: 11 Number: 2988
Today's topics:
Re: access to files in multiple combinations of folders <geoff@invalid.invalid>
Re: access to files in multiple combinations of folders <jurgenex@hotmail.com>
Convert array into list context <ryanchan404@gmail.com>
Re: Convert array into list context (Alan Curry)
Re: Convert array into list context <ryanchan404@gmail.com>
Re: Convert array into list context sln@netherlands.com
Re: Converting HTML to PDF with Webkit <hjp-usenet2@hjp.at>
Re: Converting HTML to PDF with Webkit <rvtol+usenet@xs4all.nl>
Re: Creating pdf output file <john@castleamber.com>
Re: Creating pdf output file <cartercc@gmail.com>
Re: Creating pdf output file <bobm3@worthless.info>
Re: Creating pdf output file <john@castleamber.com>
Re: Creating pdf output file <RedGrittyBrick@SpamWeary.invalid>
Re: Creating pdf output file <bobm3@worthless.info>
debugging regex expression in gui <pengyu.ut@gmail.com>
Re: graphics <hjp-usenet2@hjp.at>
How to grep using an array of patterns? <pengyu.ut@gmail.com>
Re: How to grep using an array of patterns? <willem@turtle.stack.nl>
Re: How to grep using an array of patterns? <pengyu.ut@gmail.com>
Negative Lookbehind and Wildcards <pengyu.ut@gmail.com>
Re: Negative Lookbehind and Wildcards <rvtol+usenet@xs4all.nl>
Where is -e (file test operator) in man? <pengyu.ut@gmail.com>
Re: Where is -e (file test operator) in man? <eric.amick@verizon.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 13 Jun 2010 08:35:02 +0100
From: Geoff <geoff@invalid.invalid>
Subject: Re: access to files in multiple combinations of folders?
Message-Id: <cg2916plrf55phjk19fr86rat01erq7kse@4ax.com>
On Fri, 11 Jun 2010 19:04:33 -0700, Jürgen Exner
<jurgenex@hotmail.com> wrote:
>Geoff <geoff@invalid.invalid> wrote:
>>On Fri, 11 Jun 2010 04:34:53 -0700, Jürgen Exner
>>>Do you have a question that is related to Perl, too?
>>
>>yes, in the sense that I am looking for an alternative to the use of
>>.htaccess, and this could be Perl. PHP or Javascript.
>
>...or C or Lisp or Fortran or Haskell or any other of hundreds of
>programming languages.....
>That doesn't make your question a C or Lisp or Fortran question.
OK - so which group should I have asked the question?!
Geoff
>jue
------------------------------
Date: Sun, 13 Jun 2010 03:44:26 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: access to files in multiple combinations of folders?
Message-Id: <5fd916l4d9etc4cqakq4eqhgpufrko4tav@4ax.com>
Geoff <geoff@invalid.invalid> wrote:
>On Fri, 11 Jun 2010 19:04:33 -0700, Jürgen Exner
><jurgenex@hotmail.com> wrote:
>
>>Geoff <geoff@invalid.invalid> wrote:
>>>On Fri, 11 Jun 2010 04:34:53 -0700, Jürgen Exner
>>>>Do you have a question that is related to Perl, too?
>>>
>>>yes, in the sense that I am looking for an alternative to the use of
>>>.htaccess, and this could be Perl. PHP or Javascript.
>>
>>...or C or Lisp or Fortran or Haskell or any other of hundreds of
>>programming languages.....
>>That doesn't make your question a C or Lisp or Fortran question.
>
>OK - so which group should I have asked the question?!
Your question appears to be related to authoring for the WWW. So
somewhere in the infosystems.WWW hierachie seems to be reasonable.
jue
------------------------------
Date: Sun, 13 Jun 2010 01:42:54 -0700 (PDT)
From: Ryan Chan <ryanchan404@gmail.com>
Subject: Convert array into list context
Message-Id: <bd4ceb9d-6a3e-4b5c-8d72-cb81c2a3c83f@23g2000pre.googlegroups.com>
Consider the simple code.
============
my @a = (1,2,'c');
my $s = ('a' , @a);
print $s;
============
How to print out 'c' instead of 3?
------------------------------
Date: Sun, 13 Jun 2010 09:53:57 +0000 (UTC)
From: pacman@kosh.dhis.org (Alan Curry)
Subject: Re: Convert array into list context
Message-Id: <hv29rl$s72$1@speranza.aioe.org>
Ryan Chan <ryanchan404@gmail.com> wrote:
>Consider the simple code.
>
>============
>my @a = (1,2,'c');
>
>my $s = ('a' , @a);
>print $s;
>============
>
>
>How to print out 'c' instead of 3?
>
Oh that wacky scalar-context comma operator! You were hoping it would
flatten the list and then act as if the elements of @a had been
separated by scalar-context comma operators, yielding the last element
of the flattened list? Too clever.
my $s = ('a' , @a)[-1];
In addition to actually working, the [-1] index also makes it obvious to
the later maintenance programmer that you wanted the last element of the
list. Explicit is better than implicit...
--
Alan Curry
------------------------------
Date: Sun, 13 Jun 2010 06:24:05 -0700 (PDT)
From: Ryan Chan <ryanchan404@gmail.com>
Subject: Re: Convert array into list context
Message-Id: <8af06c26-d61f-4e9e-81bb-e684c7642cfc@e34g2000pra.googlegroups.com>
Hi,
On 6=E6=9C=8813=E6=97=A5, =E4=B8=8B=E5=8D=885=E6=99=8253=E5=88=86, pac...@k=
osh.dhis.org (Alan Curry) wrote:
> my $s =3D ('a' , @a)[-1];
>
Yes, this work. Thanks.
But it is ambiguous that we don't know when the array is being
flattened, e.g. why not @a is being taken out.
------------------------------
Date: Sun, 13 Jun 2010 07:17:44 -0700
From: sln@netherlands.com
Subject: Re: Convert array into list context
Message-Id: <03p9161goccme83lv6na1q4lb5uipml7kg@4ax.com>
On Sun, 13 Jun 2010 01:42:54 -0700 (PDT), Ryan Chan <ryanchan404@gmail.com> wrote:
>Consider the simple code.
>
>============
>my @a = (1,2,'c');
>
>my $s = ('a' , @a);
>print $s;
>============
>
>
>How to print out 'c' instead of 3?
@a is viewed in scalar context giving the # of elements.
You can expand the RHS a couple of ways.
With the Array slice notation on the list element -
$s = ('a' , @a[0..$#a]);
or index the list where [-1] gets last element of the expanded list -
$s = ('a' , @a)[-1]; # best way
or, a little of both -
$s = ('a' , @a[0..$#a])[-1]; # redundant
-sln
------------------------------
Date: Sun, 13 Jun 2010 11:28:14 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Converting HTML to PDF with Webkit
Message-Id: <slrni1995i.4fp.hjp-usenet2@hrunkner.hjp.at>
On 2010-06-11 23:58, Dr.Ruud <rvtol+usenet@xs4all.nl> wrote:
> Peter J. Holzer wrote:
>> On 2010-06-10 07:02, Chris Nehren <apeiron@invalid.isuckatdomains.net> wrote:
>>> Not a module, per se, but I've had success with wkhtmltopdf. See
>>> http://code.google.com/p/wkhtmltopdf/ for more info.
>>
>> Thanks, but after playing with it for a bit I found two problems:
>>
>> 1) It pretends to be a screen device, not a printing device (so for a
>> stylesheet which contain both @media print and @media screen sections
>> it chooses the wrong ones).
>> 2) It sometimes makes a pagebreak in the middle of a line (so the upper
>> half of the line is on page 1 and the lower half of the line is on
>> page 2).
>>
>> It looks like the tool renders the page the same way as a browser on
>> screen and then cuts the result into pages.
>
> This should help:
> --print-media-type
That was the option I was looking for. I guess I didn't expect to find
an option which I consider extremely important (in fact, I think it
should be the default) to be hidden under "less common command
switches".
> "page-break-inside: avoid;"
I see that I wasn't clear enough what I meant with "a pagebreak in the
middle of a line", so some screenshots may help:
http://www.hjp.at/junk/ss-wkhtmltopdf1.png
http://www.hjp.at/junk/ss-wkhtmltopdf2.png
As you can see, the last line of the page is split *horizontally*
slightly above the baseline in both cases - the descenders appear at the
top of the next page. That's clearly a bug and not something
"page-break-inside: avoid;" is supposed to fix. "page-break-inside:
avoid;" avoids pagebreaks within an element, e.g. a paragraph, but that
isn't the problem here.
> http://www.smashingmagazine.com/2007/02/21/printing-the-web-solutions-and-techniques/
Nice collection of links, although I'm not sure why you mention them.
> http://code.google.com/p/wkhtmltopdf/issues/detail?id=9
Yup, my problem number 2 is mentioned in comment 4 here. I already found
that before posting.
> http://code.google.com/p/wkhtmltopdf/issues/detail?id=57
Different problem.
> http://search.cpan.org/~tbr/WKHTMLTOPDF-0.02/lib/WKHTMLTOPDF.pm
Ouch! My eyes! Couldn't he have named the thing WkHTMLtoPDF of
WkHtmlToPdf, or something? ;-).
hp
------------------------------
Date: Sun, 13 Jun 2010 13:56:48 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Converting HTML to PDF with Webkit
Message-Id: <4c14c781$0$22918$e4fe514c@news.xs4all.nl>
Peter J. Holzer wrote:
> On 2010-06-11 23:58, Dr.Ruud <rvtol+usenet@xs4all.nl> wrote:
>> This should help:
>> --print-media-type
>
> That was the option I was looking for. I guess I didn't expect to find
> an option which I consider extremely important (in fact, I think it
> should be the default) to be hidden under "less common command
> switches".
Yes, I also don't understand why "they" did it like that, it makes it
all unnecessary less easy to understand.
But it still all works reasonably well, we create many thousands of
unique PDFs daily with it.
>> "page-break-inside: avoid;"
>
> I see that I wasn't clear enough what I meant with "a pagebreak in the
> middle of a line" [...]
> the last line of the page is split *horizontally*
> slightly above the baseline
That's what I understood, and I assumed that you could prevent that by
giving the element that attribute. BTW, the default page size is A4.
The manual says:
<quote>
Page Breaking
The current page breaking algorithm of WebKit leaves much to be
desired. Basically webkit will render everything into one long page,
and then cut it up into pages. This means that if you have two columns
of text where one is vertically shifted by half a line, then webkit
will cut a line into to pieces display the top half on one page, and
the bottom half on another page. It will also break image in two and so
on. If you are using the patched version of QT you can use the CSS
page-break-inside property to remedy this somewhat. There is no easy
solution to this problem, until this is solved try organising your HTML
documents such that it contains many lines on which pages can be cut
cleanly.
See also:
<http://code.google.com/p/wkhtmltopdf/issues/detail?id=9>,
<http://code.google.com/p/wkhtmltopdf/issues/detail?id=33> and
<http://code.google.com/p/wkhtmltopdf/issues/detail?id=57>.
</quote>
Fonts (and Qt's QPrinter::ScreenResolution) also can cause issues:
http://code.google.com/p/wkhtmltopdf/issues/detail?id=72
--
Ruud
------------------------------
Date: Sat, 12 Jun 2010 17:28:22 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: Creating pdf output file
Message-Id: <87hbl7x4vt.fsf@castleamber.com>
HerbF@earthlink.net writes:
> John Bokma wrote:
>
>>HerbF@earthlink.net writes:
>>
>>> I have a Perl script that generates an HTML page and sends it to a
>>> recipient via email. I would prefer to send the recipient a pdf document
>>> instead of the HTML page. Is there "an easy" method of doing this within
>>> the Perl script?
>>
>>Check out the "Converting HTML to PDF with Webkit" thread of last week,
>>especially the answers by Dr.Ruud ;-)
>
> Thanks, John, I did. It appears that webkit is an external program that
> reads a screen and converts it to pdf. I need to do this within Perl, on
> my remote (CGI) server.
Clear. I have only limited experience with PDF::API2::Lite [1] which is
most likely too low-level for this. Unless you want to parse the HTML
and render it to HTML yourself (which depending on the complexity might
not be as bad as it sounds).
[1] http://johnbokma.com/mexit/2009/02/24/jpeg-to-pdf-using-perl.html
--
John Bokma j3b
Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
------------------------------
Date: Sat, 12 Jun 2010 17:45:34 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Creating pdf output file
Message-Id: <2eb36206-b7d8-4391-a9f6-9081a80d57b0@z10g2000yqb.googlegroups.com>
On Jun 12, 12:27=A0pm, He...@earthlink.net wrote:
> I have a Perl script that generates an HTML page and sends it to a
> recipient via email. I would prefer to send the recipient a pdf document
> instead of the HTML page. Is there "an easy" method of doing this within
> the Perl script?
I create great numbers of PDF documents for various purposes. Some are
reports, but some are collections of PDF documents that we send to
directors/managers to print and distribute (as hard copies) to the
people that they direct/manage.
I use PDF::API2, and can report that it performs reliably and has
never failed.
On the downside, I haven't found very good documentation, and I'm sure
that my code has a lot of cruft that results from sheer ignorance.
I find that it's very similar to generating HTML using absolute
positioning. Once you get over the grunt work of creating the
template, you can generate as many documents as you need to.
If all you need is an 'easy' method to send one document, then
PDF::API2 probably will be too much work for the benefit you will
derive. However, if you need to generate many PDF files, it may be
exactly what you need.
If you need some code, contact me privately at ccc31807 at yahoo dot
com and I'll send you one of my scripts.
CC.
------------------------------
Date: Sat, 12 Jun 2010 21:00:07 -0400
From: bobmct <bobm3@worthless.info>
Subject: Re: Creating pdf output file
Message-Id: <59b816ll3qm5ll3ol4tm9v87nmg7nnopkt@4ax.com>
Herb;
What platform is your cgi running on?
In my case I often product complex reports from perl. So I write them
to a text file then use a free winblows utility text2pdf that does a
GREAT job virtually instantaneously. If you can write your html code
to a file on Windoze then this utility would work for you.
Good luck
------------------------------
Date: Sat, 12 Jun 2010 23:36:42 -0500
From: John Bokma <john@castleamber.com>
Subject: Re: Creating pdf output file
Message-Id: <878w6jsg4l.fsf@castleamber.com>
bobmct <bobm3@worthless.info> writes:
> to a text file then use a free winblows utility text2pdf that does a
I guess you mean Windows.
Thank you for keeping baby talk out of this group,
--
John Bokma j3b
Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
------------------------------
Date: Sun, 13 Jun 2010 09:10:22 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.invalid>
Subject: Re: Creating pdf output file
Message-Id: <PaadnQ8MscHiPYnRnZ2dnUVZ8iidnZ2d@bt.com>
On 13/06/2010 02:00, bobmct wrote:
> In my case I often product complex reports from perl. So I write them
> to a text file then use a free winblows utility text2pdf that does a
> GREAT job virtually instantaneously. If you can write your html code
> to a file on Windoze then this utility would work for you.
Which one? There seem to be many programs named text2pdf.
* Phil Smith's text2pdf
* FyTek's text2pdf
* SANFACE's text2pdf or txt2pdf
* A. Riazi's text2pdf
* Navi's text2pdf
* Keith Vetter's text2pdf
--
RGB
------------------------------
Date: Sun, 13 Jun 2010 06:34:56 -0400
From: bobmct <bobm3@worthless.info>
Subject: Re: Creating pdf output file
Message-Id: <u0d916tasogscr4ig379cpvf8c35ft2or3@4ax.com>
On Sun, 13 Jun 2010 09:10:22 +0100, RedGrittyBrick
<RedGrittyBrick@SpamWeary.invalid> wrote:
>On 13/06/2010 02:00, bobmct wrote:
>> In my case I often product complex reports from perl. So I write them
>> to a text file then use a free winblows utility text2pdf that does a
>> GREAT job virtually instantaneously. If you can write your html code
>> to a file on Windoze then this utility would work for you.
>
>Which one? There seem to be many programs named text2pdf.
> * Phil Smith's text2pdf
> * FyTek's text2pdf
> * SANFACE's text2pdf or txt2pdf
> * A. Riazi's text2pdf
> * Navi's text2pdf
> * Keith Vetter's text2pdf
I use Phil Smith's version to which I've expanded to handle upwards of
2K pages for very large historical reports.
------------------------------
Date: Sat, 12 Jun 2010 20:21:01 -0700 (PDT)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: debugging regex expression in gui
Message-Id: <b9dd80ca-cf05-4228-baf4-fe5bb61a5132@i31g2000yqm.googlegroups.com>
I want to debug regex to make sure that my regex is correct. A google
search give me several debuggers, but I'm not sure which one best fit
my needs. Essentially, I'm looking a tool like http://kodos.sourceforge.net/
(but this is for python), so that I can input the regex and the string
and see the colored results immediately.
Would you please let me know what is the appropriate tool for this
purpose for perl?
------------------------------
Date: Sun, 13 Jun 2010 12:56:51 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: graphics
Message-Id: <slrni19ebj.4fp.hjp-usenet2@hrunkner.hjp.at>
On 2010-06-11 03:19, Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> On 2010-06-10, RedGrittyBrick <RedGrittyBrick@spamweary.invalid> wrote:
>>> Generating PDF might be easy (did not try it),
>>> and it is much easier to print...
>
>> This isn't something I find any problems with. Most laser printers above
>> entry level will support PostScript printing. Some of them support PDF
>> printing. Most (if not all) Unix/Linux systems will have print systems
>> that can rasterise PostScript for non-Postscript printers.
>
> You have a wrong (IMO) metric of "having problems". PS is a
> programming language. There is no way to "verify" PS or debug PS:
> there is no way to know whether a given PS file will print on your
> neighbor's PS printer except for printing it.
>
> Likewise, if you can rasterize PS with one version of GS, this does
> not imply that it would rasterize with a different version of GS.
> Basically, PS leads you in the same messy can of worms as most other
> programming languages (only it has no debuggers or development tools).
>
> PDF, on the other hand, contains just DATA, not PROGRAM.
There is no clear-cut boundary between data and program. True, PDF isn't
turing-complete (unless it contains JavaScript), but that doesn't make
the interpreter much simpler. The exclusion of flow-control from the PDF
language has other advantages, though: For example, you can determine
page boundaries by a static analysis of the file, which isn't possible
in Postscript (although there is a convention to use special comments
for that).
> It must be easy to verify (never tried it); then any non-buggy
> implementation would be able to rasterize it.
Newer versions of Acrobat Reader won't rasterize some PDFs generated by
Acrobat 10 years ago, because some features of early PDF versions have
been removed in later versions. OTOH, I am not aware of any
backwards-compatibility issues with PostScript (which also went through
a lot less revisions, although it is older).
>>> Myself, I would go through enscript or TeX - this would cover the
>>> typesetting needs
>>
>> I also use enscript and a2ps. I found writing TeX (or rather LaTeX)
>> still needs a lot of markup and the production chain can be complicated
>> and prone to generating mysterious error messages. What TeX toolset do
>> you use?
>
> LaTeX + ams.
LaTeX (or rather TeX) is a programming language, too.
It does have the advantage over page description languages like PDF of
PostScript that it handles much of the layout automatically (and
produces rather nice output).
>> prefer keeping source matter in a plain text form rather than in any
>> proprietary form that is likely to become obsolete and unreadable.
>
> It is exactly the opposite with me. LaTeX is known to be
> non-backward-compatible. So I keep data in proprietary form with a
> known script for to-LaTeX conversion.
Who is the proprietor of your proprietary format? You? Then you
naturally won't have a problem, as you know and control the format.
Somebody else? Then you may run into problems when that person or
company stops supporting that format or alters it in an incompatible
way.
hp
------------------------------
Date: Sun, 13 Jun 2010 07:41:06 -0700 (PDT)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: How to grep using an array of patterns?
Message-Id: <58c2c6bb-493c-4bc4-9363-6351121ec71e@w31g2000yqb.googlegroups.com>
If I only have a small number of patterns(say 3), I can just spell out
the matching code as below.
grep {/$pattern1$/ or /$pattern2$/ or /$pattern3$/} @array;
But if I have @patterns with many patterns that I want grep, the above
way doesn't work. I'm wondering what is the best way to grep many
patterns.
------------------------------
Date: Sun, 13 Jun 2010 14:46:03 +0000 (UTC)
From: Willem <willem@turtle.stack.nl>
Subject: Re: How to grep using an array of patterns?
Message-Id: <slrni19rpb.2kl4.willem@turtle.stack.nl>
Peng Yu wrote:
) If I only have a small number of patterns(say 3), I can just spell out
) the matching code as below.
)
) grep {/$pattern1$/ or /$pattern2$/ or /$pattern3$/} @array;
)
) But if I have @patterns with many patterns that I want grep, the above
) way doesn't work. I'm wondering what is the best way to grep many
) patterns.
That depends on a number of things, such as how many items and times you
will be matching with the same set of patterns, how complex these patterns
are, and if you value maintainability over execution speed.
Possibilities I can think of offhand:
- Nested greps (two possible ways to nest)
- Nested greps with precompiled regexes
- Combining search patterns into one big regex
And there are probably more.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Sun, 13 Jun 2010 07:53:43 -0700 (PDT)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: Re: How to grep using an array of patterns?
Message-Id: <a368b600-9cf4-4265-be67-496c3ae8eaa7@y4g2000yqy.googlegroups.com>
On Jun 13, 9:46=A0am, Willem <wil...@turtle.stack.nl> wrote:
> Peng Yu wrote:
>
> ) If I only have a small number of patterns(say 3), I can just spell out
> ) the matching code as below.
> )
> ) grep {/$pattern1$/ or /$pattern2$/ =A0or /$pattern3$/} @array;
> )
> ) But if I have @patterns with many patterns that I want grep, the above
> ) way doesn't work. I'm wondering what is the best way to grep many
> ) patterns.
>
> That depends on a number of things, such as how many items and times you
> will be matching with the same set of patterns, how complex these pattern=
s
> are, and if you value maintainability over execution speed.
Let's say I have only 10 simple patterns (just have non-special
characters, a-z, A-Z, _, and \.) and they are mutually exclusive (if a
file match one pattern it can not match another).
> Possibilities I can think of offhand:
> - Nested greps (two possible ways to nest)
It seems that the above one is the simplest solution for this
particular problem. Would you pleas show me some code on how to use
nested greps?
> - Nested greps with precompiled regexes
> - Combining search patterns into one big regex
>
> And there are probably more.
>
> SaSW, Willem
> --
> Disclaimer: I am in no way responsible for any of the statements
> =A0 =A0 =A0 =A0 =A0 =A0 made in the above text. For all I know I might be
> =A0 =A0 =A0 =A0 =A0 =A0 drugged or something..
> =A0 =A0 =A0 =A0 =A0 =A0 No I'm not paranoid. You all think I'm paranoid, =
don't you !
> #EOT
------------------------------
Date: Sun, 13 Jun 2010 05:20:42 -0700 (PDT)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: Negative Lookbehind and Wildcards
Message-Id: <3b5eacb7-1ed1-4317-9347-e61994248cba@r27g2000yqb.googlegroups.com>
I try to match .cpp files that doesn't start with 'main'. But the grep
command below match all the .cpp files. I know that \w* tries to match
as long as possible. Do you know how to fix the regex to get all
the .cpp files that doesn't start with 'main'?
#!/usr/bin/env perl
use strict;
use warnings;
my @array=qw(main.cpp main_xx.cpp uuu.cpp vvv.cpp);
my @non_main_cpp=grep /(?<!main)\w*.cpp/, @array;
print join(', ', @non_main_cpp), "\n";
------------------------------
Date: Sun, 13 Jun 2010 16:03:00 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Negative Lookbehind and Wildcards
Message-Id: <4c14e514$0$22917$e4fe514c@news.xs4all.nl>
Peng Yu wrote:
> I try to match .cpp files that doesn't start with 'main'. But the grep
> command below match all the .cpp files. I know that \w* tries to match
> as long as possible. Do you know how to fix the regex to get all
> the .cpp files that doesn't start with 'main'?
>
> #!/usr/bin/env perl
>
> use strict;
> use warnings;
>
> my @array=qw(main.cpp main_xx.cpp uuu.cpp vvv.cpp);
>
> my @non_main_cpp=grep /(?<!main)\w*.cpp/, @array;
> print join(', ', @non_main_cpp), "\n";
There are many ways to do this, it all depends on what you need in the end:
perl -wle '
my @filenames = qw( 1.txt main.txt 1.cpp main_01.cpp );
print for "", grep !/^main/, @filenames;
print for "", grep !/\Amain/ && /\.cpp\z/, @filenames;
print for "", grep {!/\Amain/ and /\.cpp\z/} @filenames;
print for "", grep +(!/\Amain/ and /\.cpp\z/), @filenames;
'
1.txt
1.cpp
1.cpp
1.cpp
1.cpp
--
Ruud
------------------------------
Date: Sun, 13 Jun 2010 08:00:08 -0700 (PDT)
From: Peng Yu <pengyu.ut@gmail.com>
Subject: Where is -e (file test operator) in man?
Message-Id: <575b56ed-e054-4d65-a2f1-4fef401ef7ea@g19g2000yqc.googlegroups.com>
-e is discussed in operator section in Programming Perl. But I don't
find it in man perlop. Would you please let me know where it is
document in man or perldoc?
------------------------------
Date: Sun, 13 Jun 2010 11:04:02 -0400
From: Eric Amick <eric.amick@verizon.net>
Subject: Re: Where is -e (file test operator) in man?
Message-Id: <8qs9169n193ilbkairuokqoc1lr1n9dgqr@4ax.com>
On Sun, 13 Jun 2010 08:00:08 -0700 (PDT), Peng Yu <pengyu.ut@gmail.com>
wrote:
>-e is discussed in operator section in Programming Perl. But I don't
>find it in man perlop. Would you please let me know where it is
>document in man or perldoc?
It's under -X in perlfunc.
--
Eric Amick
Columbia, MD
------------------------------
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 2988
***************************************