[31184] in Perl-Users-Digest
Perl-Users Digest, Issue: 2429 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 20 09:09:47 2009
Date: Wed, 20 May 2009 06: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 Wed, 20 May 2009 Volume: 11 Number: 2429
Today's topics:
Re: ampersand subroutine <news123@free.fr>
Re: ampersand subroutine <brian.d.foy@gmail.com>
Re: ampersand subroutine <brian.d.foy@gmail.com>
Re: ampersand subroutine <spamtrap@dot-app.org>
Re: compiled perl question. <news123@free.fr>
Re: FAQ 8.4 How do I print something out in color? <brian.d.foy@gmail.com>
Re: Generate Word and Powerpoint files <benkasminbullock@gmail.com>
Re: Generate Word and Powerpoint files <benkasminbullock@gmail.com>
Re: Generate Word and Powerpoint files <ddp23@cam.ac.uk>
new CPAN modules on Wed May 20 2009 (Randal Schwartz)
Re: One-liners: single quotes; altering first line only <peter@makholm.net>
Re: One-liners: single quotes; altering first line only <smallpond@juno.com>
Re: One-liners: single quotes; altering first line only <peter@makholm.net>
One-liners: single quotes; altering first line only; pr <a24061@ducksburg.com>
Re: One-liners: single quotes; altering first line only <someone@example.com>
Re: Outputting to PDF simply? <r.mariotti@fdcx.net>
Re: problems with writing to an output file <ameya.r.sathe@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 20 May 2009 09:18:34 +0200
From: News123 <news123@free.fr>
Subject: Re: ampersand subroutine
Message-Id: <4a13aecb$0$11312$426a74cc@news.free.fr>
Thanks for your explanations Uri and Juergen.
As you said I misunderstood the term 'visible' and I
always called own functions with '()', so never fell
into the problem of calling a sub before its declaration
For 99% of perl code I would give following advise:
Don't use ampersand for calling functions
Don't use function prototypes
Don't declare functions separately before their definition.
Group your function definitions either roughly bottom up at the
beginning of your script or group them all top down at the end of your
script.
In the latter case I'd suggest an explicit exit() statement before the
function definitions in order to signal to a person reading the code,
that no more code outside of function definitions will follow (except of
course for potential BEGIN blocks)
bye
Jürgen Exner wrote:
> News123 <news123@free.fr> wrote:
>> I'm a little surprised by one of Guy's and one of your statements.
>>
>>
>> Jürgen Exner wrote:
>>> "Guy" <someone@somewhere.nb.ca> wrote:
>>>> So I read that you can omit the ampersand if "the compiler sees the
>>>> subroutine definition before invocation or..."
>> Please see my example at the end of the post.
>> the function is declared after the call and things work fine.
>
> That's because (as Tad explained earlier) you are calling it with an
> argument list, i.e. with paranthesis. If you omit the paranthesis then
> you will get an error about bareword not allowed.
>
>>> 3: the ampersand is not "a thing of the past". It modifies the calling
>>> semantic, such that
>>> a) prototypes are overridden
>>> b) @_ is visible to the called sub
>> @_ is also visible in my example, but you say the ampersand is needed.
>> I guess you mean soething different, but I don't understand it.
>
> Uri already explained that part.
>
> jue
------------------------------
Date: Wed, 20 May 2009 04:37:00 -0400
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: ampersand subroutine
Message-Id: <200520090437003168%brian.d.foy@gmail.com>
In article <slrnh163a4.t5a.hjp-usenet2@hrunkner.hjp.at>, Peter J.
Holzer <hjp-usenet2@hjp.at> wrote:
> There is one place where you still need the ampersand - if you need to
> take a reference to a sub.
That's why we still talk about the & in Learning Perl. It makes the sub
look more like what people already know about the other variable types.
------------------------------
Date: Wed, 20 May 2009 04:40:40 -0400
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: ampersand subroutine
Message-Id: <200520090440406385%brian.d.foy@gmail.com>
In article <4a121bad$0$23761$9a566e8b@news.aliant.net>, Guy
<someone@somewhere.nb.ca> wrote:
> I've seen some code that call user subroutines without the ampersand. I
> didn't know you could do that.
>
> "BTW, I went out and bought Learning Perl to help with my Intermediate
> Perl."
>
> So I read that you can omit the ampersand if "the compiler sees the
> subroutine definition before invocation or..."
Remember that Learning Perl purposedly ignores a lot of details so you
can get started as a Perl programmer a lot sooner than you would if you
have to digest all of the Perl documentation.
The leading ampersand on subroutine names is a first-week beginner
thing before you've gone through perlfunc to see what Perl already
defines. Often our students will redefine built-ins (log is a favorite)
during their first couple of days of Perl.
------------------------------
Date: Wed, 20 May 2009 06:30:42 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: ampersand subroutine
Message-Id: <m1vdnwjcbx.fsf@dot-app.org>
News123 <news123@free.fr> writes:
> In the latter case I'd suggest an explicit exit() statement before the
> function definitions in order to signal to a person reading the code,
> that no more code outside of function definitions will follow
If you're communicating to a person, comments are far clearer:
# End main code body
# Function definitions follow
Use exit() for its intended purpose, explicitly returning an exit code
to the parent process.
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Wed, 20 May 2009 09:23:25 +0200
From: News123 <news123@free.fr>
Subject: Re: compiled perl question.
Message-Id: <4a13afed$0$11312$426a74cc@news.free.fr>
http://perldoc.perl.org/
Just enter hide into the search field.
HOWEVER. Be aware, that the documentation might be for a different per
version than yours. For some new features you might find discerpancies.
Below the search field you can select the two previous main perl versions.
N.
Lawrence Statton wrote:
> DaLoverhino <DaLoveRhino@hotmail.com> writes:
>
>> On May 19, 11:45 am, Jürgen Exner <jurge...@hotmail.com> wrote:
>>> DaLoverhino <DaLoveRh...@hotmail.com> wrote:
>>>> I read somewhere that perl gets compiled to bytecodes and is run in a
>>>> perl virtual machine similar to Java. Is that true? What I'd like to
>>>> do is give a bytecode compiled version of my perl script, but not the
>>>> script itself, to prevent copying or modifying it. I'd rather not run
>>>> the script through an obfuscator.
>>> perldoc -q hide
>>>
>>> How can I hide the source for my Perl program?
>>>
>>> jue
>> Thanks, unfortunately, I don't have perldoc on my system, and I am not
>> the sys admin of our unix boxes. Can you copy/past the output of that
>> command for me onto this thread, please? Thanks.
>
> If you can't write any executable files anywhere to any filesystem
> (which is the only possible explanation for not being able to install a
> private copy of perldoc) how can you even produce any code at all?
>
>
------------------------------
Date: Wed, 20 May 2009 04:32:52 -0400
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 8.4 How do I print something out in color?
Message-Id: <200520090432528291%brian.d.foy@gmail.com>
In article <5k25e6-v7b2.ln1@osiris.mauzo.dyndns.org>, Ben Morrow
<ben@morrow.me.uk> wrote:
> Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> > On 2009-05-17, Ben Morrow <ben@morrow.me.uk> wrote:
> > >
> > > use if $^O eq "MSWin32" && -t STDOUT, "Win32::Console::ANSI";
> > >
> > > before C<use Term::ANSIColor;>.
> >
> > ??? Why not just make it part of Term::ANSIColor instead?
>
> Don't ask me, I didn't write either of the modules involved :).
You can submit patches though. They are open source, and no one sees a
patch that you don't submit. :)
------------------------------
Date: Wed, 20 May 2009 08:30:04 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Generate Word and Powerpoint files
Message-Id: <gv0f2c$9pl$1@news.eternal-september.org>
On Tue, 19 May 2009 15:23:36 +0000, Daniel Parry wrote:
> I'd like to generate word and power point files on a linux based system.
> Populated with various random words from a dictionary to create various
> different size files. I have this working for: Excel, HTML, JSON, ODT,
> PDF, RTF, Text, and XML format but stumped a bit for doc and ppt. Any
> one have any suggestions for hacks that might make these last two
> formats possible, which don't include starting up a windows instance
> somehow (^_^)
On Linux you could create your file in HTML or some other format and then
have OpenOffice.org save it in Microsoft Word's .doc or .ppt formats.
I don't know how to automate OpenOffice.org but I imagine it's possible.
------------------------------
Date: Wed, 20 May 2009 08:38:27 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Generate Word and Powerpoint files
Message-Id: <gv0fi3$9pl$2@news.eternal-september.org>
On Tue, 19 May 2009 10:41:46 -0700, smallpond wrote:
> On May 19, 11:23Â am, Daniel Parry <dd...@cam.ac.uk> wrote:
>> I'd like to generate word and power point files on a linux based
>> system. Populated with various random words from a dictionary to create
>> various different size files. I have this working for: Excel, HTML,
>> JSON, ODT, PDF, RTF, Text, and XML format but stumped a bit for doc and
>> ppt. Any one have any suggestions for hacks that might make these last
>> two formats possible, which don't include starting up a windows
>> instance somehow (^_^)
> Please post a spec for those formats.
The specs for the Office formats can be found at
http://msdn.microsoft.com/en-us/library/cc313118.aspx
------------------------------
Date: 20 May 2009 08:37:15 GMT
From: Daniel Parry <ddp23@cam.ac.uk>
Subject: Re: Generate Word and Powerpoint files
Message-Id: <slrnh17g9r.l92.ddp23@pip.srcf.ucam.org>
On 2009-05-19, smallpond <smallpond@juno.com> wrote:
> Please post a spec for those formats.
In essence, I'm after formats suitable for testing the text
extraction capabilities of the java JCR jackrabbit system. I
believe jackrabbit is moving towards using apache tika, so the
formats are likely those listed here:
http://lucene.apache.org/tika/formats.html
Though I am particularly interested in word and power point docs,
which likely means the OLE2 Compound Document format?
Best wishes,
Daniel
------------------------------
Date: Wed, 20 May 2009 04:42:26 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Wed May 20 2009
Message-Id: <KJxEEq.MHv@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
Acme-Hi-0.01
http://search.cpan.org/~robbiebow/Acme-Hi-0.01/
Say "hi" easily and in many tongues
----
Acme-MirrorTracer-2009.051914390008
http://search.cpan.org/~andya/Acme-MirrorTracer-2009.051914390008/
Do nothing.
----
Acme-PM-Paris-Meetings-200905.03
http://search.cpan.org/~dolmen/Acme-PM-Paris-Meetings-200905.03/
Get the date/time of the next Paris.pm meeting!
----
Alien-ActiveMQ-0.00001
http://search.cpan.org/~bobtfish/Alien-ActiveMQ-0.00001/
Manages installs of versions of Apache ActiveMQ, and provides a standard way to start an MQ server from perl.
----
Any-Moose-0.09
http://search.cpan.org/~flora/Any-Moose-0.09/
use Moose or Mouse modules
----
App-Framework-0.91
http://search.cpan.org/~sdprice/App-Framework-0.91/
A framework for creating applications
----
App-Framework-0.92
http://search.cpan.org/~sdprice/App-Framework-0.92/
A framework for creating applications
----
CPAN-WWW-Top100-Generator-0.05
http://search.cpan.org/~adamk/CPAN-WWW-Top100-Generator-0.05/
Create or update the website for http://ali.as/top100
----
CPANTS-Weight-0.14
http://search.cpan.org/~adamk/CPANTS-Weight-0.14/
Graph based weights for CPAN Distributions
----
CatalystX-Menu-Suckerfish-0.02
http://search.cpan.org/~converter/CatalystX-Menu-Suckerfish-0.02/
Generate HTML UL for a CSS-enhanced Suckerfish menu
----
CatalystX-Menu-Tree-0.02
http://search.cpan.org/~converter/CatalystX-Menu-Tree-0.02/
Generate Catalyst application menus
----
Class-C3-Adopt-NEXT-0.11
http://search.cpan.org/~bobtfish/Class-C3-Adopt-NEXT-0.11/
make NEXT suck less
----
Class-Mix-0.003
http://search.cpan.org/~zefram/Class-Mix-0.003/
dynamic class mixing
----
Color-Palette-0.091392
http://search.cpan.org/~rjbs/Color-Palette-0.091392/
a set of named colors
----
Config-AutoConf-0.12_2
http://search.cpan.org/~ambs/Config-AutoConf-0.12_2/
A module to implement some of AutoConf macros in pure perl.
----
Data-FetchPath-0.01
http://search.cpan.org/~ovid/Data-FetchPath-0.01/
"eval"able paths to your complex data values
----
Data-Visitor-0.25
http://search.cpan.org/~flora/Data-Visitor-0.25/
Visitor style traversal of Perl data structures
----
Devel-Dumpvar-1.05
http://search.cpan.org/~adamk/Devel-Dumpvar-1.05/
A pure-OO reimplementation of dumpvar.pl
----
Dist-Zilla-Plugin-CheckChangeLog-0.01
http://search.cpan.org/~fayland/Dist-Zilla-Plugin-CheckChangeLog-0.01/
Dist::Zilla with Changes check
----
Dist-Zilla-PluginBundle-FAYLAND-0.01
http://search.cpan.org/~fayland/Dist-Zilla-PluginBundle-FAYLAND-0.01/
Dist::Zilla like FAYLAND when you build your dists
----
Dist-Zilla-PluginBundle-RJBS-0.091390
http://search.cpan.org/~rjbs/Dist-Zilla-PluginBundle-RJBS-0.091390/
BeLike::RJBS when you build your dists
----
Graph-PetriNet-0.03
http://search.cpan.org/~drrho/Graph-PetriNet-0.03/
Perl extension for Petri Nets
----
HTML-Form-Declare-0.01
http://search.cpan.org/~shv/HTML-Form-Declare-0.01/
Object description of the form elements
----
HTML-Form-Declare-0.01_l
http://search.cpan.org/~shv/HTML-Form-Declare-0.01_l/
Object description of the form elements
----
HTML-Form-Declare-0.02_l
http://search.cpan.org/~shv/HTML-Form-Declare-0.02_l/
Object description of the form elements
----
HTML-Form-Declare-0.03_l
http://search.cpan.org/~shv/HTML-Form-Declare-0.03_l/
Object description of the form elements
----
HTML-TreeBuilder-XPath-0.11
http://search.cpan.org/~mirod/HTML-TreeBuilder-XPath-0.11/
add XPath support to HTML::TreeBuilder
----
HTTP-Engine-0.1.8
http://search.cpan.org/~yappo/HTTP-Engine-0.1.8/
Web Server Gateway Interface and HTTP Server Engine Drivers (Yet Another Catalyst::Engine)
----
IPC-Open3-Utils-0.5
http://search.cpan.org/~dmuey/IPC-Open3-Utils-0.5/
Functions for facilitating some of the most common open3() uses
----
JavaScript-Framework-jQuery-0.04
http://search.cpan.org/~converter/JavaScript-Framework-jQuery-0.04/
Generate markup and code for jQuery JavaScript framework
----
JavaScript-Framework-jQuery-0.05
http://search.cpan.org/~converter/JavaScript-Framework-jQuery-0.05/
Generate markup and code for jQuery JavaScript framework
----
Jifty-0.90519
http://search.cpan.org/~alexmv/Jifty-0.90519/
an application framework
----
Jifty-DBI-0.57
http://search.cpan.org/~sartak/Jifty-DBI-0.57/
An object-relational persistence framework
----
Log-Detect-1.424
http://search.cpan.org/~wsnyder/Log-Detect-1.424/
Read logfiles to detect error and warning messages
----
Make-Cache-1.051
http://search.cpan.org/~wsnyder/Make-Cache-1.051/
Caching of object and test run information
----
Math-Polynomial-1.000
http://search.cpan.org/~mhasch/Math-Polynomial-1.000/
Perl class representing polynomials in one variable
----
Math-Polynomial-1.001
http://search.cpan.org/~mhasch/Math-Polynomial-1.001/
Perl class for polynomials in one variable
----
Module-LocalBuild-1.011
http://search.cpan.org/~wsnyder/Module-LocalBuild-1.011/
Support routines for setting up perltools area
----
Module-Runtime-0.006
http://search.cpan.org/~zefram/Module-Runtime-0.006/
runtime module handling
----
Nagios-Plugin-WWW-Mechanize-0.10
http://search.cpan.org/~tonvoon/Nagios-Plugin-WWW-Mechanize-0.10/
Login to a web page as a user and get data as a Nagios plugin
----
Net-Amazon-S3-0.51
http://search.cpan.org/~lbrocard/Net-Amazon-S3-0.51/
Use the Amazon S3 - Simple Storage Service
----
Net-Autoconfig-v1.13.2
http://search.cpan.org/~kevin/Net-Autoconfig-v1.13.2/
Perl extension for provisioning or reconfiguring network devices.
----
Net-IMAP-Client-0.93
http://search.cpan.org/~mishoo/Net-IMAP-Client-0.93/
Not so simple IMAP client library
----
Net-SloppyXMPP-0.05
http://search.cpan.org/~wilsond/Net-SloppyXMPP-0.05/
A rather sloppy XMPP client implementation
----
Net-SloppyXMPP-0.06
http://search.cpan.org/~wilsond/Net-SloppyXMPP-0.06/
A rather sloppy XMPP client implementation
----
Net-Twitter-OAuth-0.04
http://search.cpan.org/~miyagawa/Net-Twitter-OAuth-0.04/
Net::Twitter subclass that uses OAuth instead of Basic Auth
----
Net-Twitter-OAuth-0.05
http://search.cpan.org/~miyagawa/Net-Twitter-OAuth-0.05/
Net::Twitter subclass that uses OAuth instead of Basic Auth
----
ORDB-CPANTesters-0.09
http://search.cpan.org/~adamk/ORDB-CPANTesters-0.09/
An ORM for the published CPAN Testers SQLite database
----
ORDB-CPANUploads-0.04
http://search.cpan.org/~adamk/ORDB-CPANUploads-0.04/
An ORLite-based ORM Database API
----
PDL-2.4.4_03
http://search.cpan.org/~chm/PDL-2.4.4_03/
the Perl Data Language
----
POE-Component-Client-DNSBL-1.02
http://search.cpan.org/~bingos/POE-Component-Client-DNSBL-1.02/
A component that provides non-blocking DNSBL lookups
----
POE-Component-Github-0.06
http://search.cpan.org/~bingos/POE-Component-Github-0.06/
A POE component for the Github API
----
Parallel-Depend-4.03
http://search.cpan.org/~lembark/Parallel-Depend-4.03/
: Parallel-dependent dispatch of perl or shell code.
----
Parallel-Forker-1.224
http://search.cpan.org/~wsnyder/Parallel-Forker-1.224/
Parallel job forking and management
----
Parse-Method-Signatures-1.003006
http://search.cpan.org/~ash/Parse-Method-Signatures-1.003006/
Perl6 like method signature parser
----
Software-License-0.011
http://search.cpan.org/~rjbs/Software-License-0.011/
packages that provide templated software licenses
----
Solaris-ProcessMemory-0.02
http://search.cpan.org/~stocks/Solaris-ProcessMemory-0.02/
Determine process memory usage on Solaris
----
Spreadsheet-WriteExcel-Simple-Tabs-0.01
http://search.cpan.org/~mrdvt/Spreadsheet-WriteExcel-Simple-Tabs-0.01/
Simple Interface to the Spreadsheet::WriteExcel Package
----
Syntax-Highlight-Perl6-0.56
http://search.cpan.org/~azawawi/Syntax-Highlight-Perl6-0.56/
Perl 6 Syntax Highlighter
----
SystemC-Vregs-1.463
http://search.cpan.org/~wsnyder/SystemC-Vregs-1.463/
Utility routines used by vregs
----
SystemPerl-1.320
http://search.cpan.org/~wsnyder/SystemPerl-1.320/
SystemPerl Language Extension to SystemC
----
Test-Cukes-0.01
http://search.cpan.org/~gugod/Test-Cukes-0.01/
A BBD test tool inspired by Cucumber
----
Time-UTC-0.006
http://search.cpan.org/~zefram/Time-UTC-0.006/
manipulation of UTC in terms of TAI
----
Time-UTC_SLS-0.002
http://search.cpan.org/~zefram/Time-UTC_SLS-0.002/
UTC with Smoothed Leap Seconds
----
UML-Class-Simple-0.18
http://search.cpan.org/~agent/UML-Class-Simple-0.18/
Render simple UML class diagrams, by loading the code
----
Verilog-Perl-3.210
http://search.cpan.org/~wsnyder/Verilog-Perl-3.210/
----
WebService-Cath-FuncNet-0.08
http://search.cpan.org/~isillitoe/WebService-Cath-FuncNet-0.08/
Interface to the CATH FuncNet webservice
----
Yahoo-Marketing-5.06
http://search.cpan.org/~shenj/Yahoo-Marketing-5.06/
an interface for Yahoo! Search Marketing's Web Services.
----
courgette-0.1
http://search.cpan.org/~steveha/courgette-0.1/
----
ex-lib-0.07
http://search.cpan.org/~mons/ex-lib-0.07/
The same as lib, but makes relative path absolute.
----
self-init-0.01
http://search.cpan.org/~mons/self-init-0.01/
Invoke package init methods at compile time
----
tk-804.028
http://search.cpan.org/~browseruk/tk-804.028/
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Wed, 20 May 2009 15:07:54 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: One-liners: single quotes; altering first line only; printing the changes?
Message-Id: <873aaz3ot1.fsf@vps1.hacking.dk>
smallpond <smallpond@juno.com> writes:
>> 2. Is it possible to tell the command to look at the first line of
>> each file only? (These were very large files.)
>>
>
> s/UTF8/UTF-8/ if 1 .. 1; # use the line range op
Only changes the first line in the first file. You have to reset $. at
some point. But this works:
perl -pi -e 's/.../.../ if 1..1; close ARGV if eof;' *
I don't know why I insisted on using next which forced me to close
before the substitution.
//Makholm
------------------------------
Date: Wed, 20 May 2009 05:49:52 -0700 (PDT)
From: smallpond <smallpond@juno.com>
Subject: Re: One-liners: single quotes; altering first line only; printing the changes?
Message-Id: <c291709f-fa4c-4970-9288-81b4e7733e01@z19g2000vbz.googlegroups.com>
On May 20, 7:20=A0am, Adam Funk <a24...@ducksburg.com> wrote:
> I had some very large RDF-XML files that had been incorrectly
> generated with the prolog
>
> <?xml version=3D'1.0' encoding=3D'UTF8'?>
>
> which I wanted to change to
>
> <?xml version=3D'1.0' encoding=3D'UTF-8'?>
>
> so I used the following command.
>
> perl -pi.bak -e 's!^(<\?xml version=3D.1\.0. encoding=3D.)UTF8(.\?\>)!\1U=
TF-8\2!' *.rdf
>
> It worked, but I have three questions about doing it better.
>
>
> 2. Is it possible to tell the command to look at the first line of
> =A0 =A0each file only? =A0(These were very large files.)
>
s/UTF8/UTF-8/ if 1 .. 1; # use the line range op
------------------------------
Date: Wed, 20 May 2009 15:01:17 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: One-liners: single quotes; altering first line only; printing the changes?
Message-Id: <87ab582ajm.fsf@vps1.hacking.dk>
"John W. Krahn" <someone@example.com> writes:
>> 2. Is it possible to tell the command to look at the first line of
>> each file only? (These were very large files.)
>
> No. Unless you only want one line left in the new files.
You could do something like:
perl -pi -e 'close ARGV if eof; next if ($. > 1)..0; s/.../.../;'
it would still read every line, but only the first would be
processed. Tested, but I'm not sure I would recommend it.
//Makholm
------------------------------
Date: Wed, 20 May 2009 12:20:08 +0100
From: Adam Funk <a24061@ducksburg.com>
Subject: One-liners: single quotes; altering first line only; printing the changes?
Message-Id: <8k5de6xveu.ln2@news.ducksburg.com>
I had some very large RDF-XML files that had been incorrectly
generated with the prolog
<?xml version='1.0' encoding='UTF8'?>
which I wanted to change to
<?xml version='1.0' encoding='UTF-8'?>
so I used the following command.
perl -pi.bak -e 's!^(<\?xml version=.1\.0. encoding=.)UTF8(.\?\>)!\1UTF-8\2!' *.rdf
It worked, but I have three questions about doing it better.
1. Is there any way to specify single quotes (') in the pattern? (I
realize this is at least as much of a shell problem as a Perl
problem; this is in bash on GNU/Linux.)
2. Is it possible to tell the command to look at the first line of
each file only? (These were very large files.)
3. Is it possible to make a perl -i command print to STDOUT the
changes it makes (and only the changed lines)?
Thanks,
Adam
--
| _
| ( ) ASCII Ribbon Campaign
| X Against HTML email & news
| / \ www.asciiribbon.org
------------------------------
Date: Wed, 20 May 2009 05:35:17 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: One-liners: single quotes; altering first line only; printing the changes?
Message-Id: <aOSQl.66444$uD3.57797@newsfe20.iad>
Adam Funk wrote:
> I had some very large RDF-XML files that had been incorrectly
> generated with the prolog
>
> <?xml version='1.0' encoding='UTF8'?>
>
> which I wanted to change to
>
> <?xml version='1.0' encoding='UTF-8'?>
>
> so I used the following command.
>
> perl -pi.bak -e 's!^(<\?xml version=.1\.0. encoding=.)UTF8(.\?\>)!\1UTF-8\2!' *.rdf
You should use $1 and $2 in the replacement string instead of \1 and \2.
> It worked, but I have three questions about doing it better.
>
> 1. Is there any way to specify single quotes (') in the pattern? (I
> realize this is at least as much of a shell problem as a Perl
> problem; this is in bash on GNU/Linux.)
$ perl -le'print "\047" x 10'
''''''''''
> 2. Is it possible to tell the command to look at the first line of
> each file only? (These were very large files.)
No. Unless you only want one line left in the new files.
> 3. Is it possible to make a perl -i command print to STDOUT the
> changes it makes (and only the changed lines)?
Yes, but only if you explicitly use the STDOUT filehandle because with
the -i switch the default output filehandle is ARGVOUT.
John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
------------------------------
Date: Tue, 19 May 2009 22:45:29 -0400
From: bobmct <r.mariotti@fdcx.net>
Subject: Re: Outputting to PDF simply?
Message-Id: <1lr61597mof2n812pri90e8jcaj40olqam@4ax.com>
Thanks gents!
You've all given me good feedback to research and dabble with.
Much appreciated. B
------------------------------
Date: Wed, 20 May 2009 01:21:51 -0700 (PDT)
From: Ameya <ameya.r.sathe@gmail.com>
Subject: Re: problems with writing to an output file
Message-Id: <9e35232f-da99-4780-8b06-772d64b24e2a@j12g2000vbl.googlegroups.com>
On May 15, 3:37=A0pm, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> Ameya <ameya.r.sa...@gmail.com> wrote:
>
> [writing to a file]
>
>
>
>
>
> >What could be the problem and how can I get my values to print in the
> >file. Following is the code snippet explaining the read and write
> >commands I use in my code.
>
> >********************************************
> >open my $fin, '<', $inFile or die "could not open file '$inFile' $!";
> ># Open the file for reading, $inFile is a CSV file
> >while (my $line =3D <$fh>) {
> > =A0 =A0chomp($line);
> > =A0 =A0...........
> > =A0 =A0.........
> > =A0 =A0$a =3D $line;
> >}
>
> >print $fout "$a\n" or die "Can't print in the file $outFile: $!"; #
> >There is no value of $a in $outFile
> >print $fout "Hello\n" or die "Can't print in the file $outFile: $!"; #
> >There is no "Hello" statement in $outFile
> >print "Hello\n" or die "Can't print in the file $outFile: $!"; #Prints
> >Hello on the screen
> >************************************************
>
> In the code you are showing above you never open $fout.
>
> That may or may not be a problem (maybe you are opening it in the part
> you snipped), but we cannot analyse something that we cannot see. Please
> post a minimal, but complete program, strict and warnings clean, that we
> can run and that demonstrates your problem.
>
> jue- Hide quoted text -
>
> - Show quoted text -
I have made opened all the file Ids necessary for reading and writing.
As I said this is not the complete code but a part of it. Following is
the complete code:
****************************************************************
#!/usr/bin/perl
use strict; # Variable declaration is required before use
use warnings;
use FileHandle;
my $path =3D "L:/adio/we/asathe/VestasLoadsData/Turbine7/200710/";
my $year =3D 2007;
my $month =3D 10;
my @columns;
my $tStatus;
my @yawDir;
my $sigCount =3D 0;
my $meanYaw =3D "";
chdir('L:/adio/we/asathe/VestasLoadsData/Turbine7/200710/') or die
"Can't change directory: $!\n";
my $command =3D "ls -1 ".$path." > D:/asathe/FLC/PROGS/tmp";
my $yawFile =3D "D:/asathe/FLC/PROGS/test.txt";
open my $fout, '>', $yawFile or die "could not open file '$yawFile'
$!";
system($command);
my $inFile =3D "D:/asathe/FLC/PROGS/tmp";
open my $fin, '<', $inFile or die "could not open file '$inFile' $!";
# Open the file for reading
while (my $file =3D <$fin>) {
chomp($file);
print "Filename is $file\n";
open my $fh, '<', $file or die "could not open file '$file' $!"; #
Open the file for reading
while (my $line =3D <$fh>) {
chomp($line);
my $lineNum =3D $.;
if ($lineNum =3D=3D 1 || $lineNum =3D=3D 2) {
next;
}
@columns =3D split /;/, $line;
if ($lineNum =3D=3D 3) {
$tStatus =3D $columns[10];
if ($tStatus !=3D 3) {
last;
}
}
if ($lineNum %2 !=3D 0) {
$yawDir[$sigCount++] =3D $columns[5];
}
}
close $fh;
if ($tStatus =3D=3D 3) {
print "Status =3D $tStatus\n";
$meanYaw =3D eval(join("+", @yawDir)) / @yawDir;
print "$meanYaw\n";
print $fout "%.3f\n", $meanYaw or die "Can't print in the file
$yawFile: $!";
print "Time taken =3D ";
print time - "$^T\n";
print " sec\n";
} else {
print "Out of Loop\n";
}
$sigCount =3D 0;
}
close $fin;
close $fout;
***************************************************************************=
**
------------------------------
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 V11 Issue 2429
***************************************