logo       


Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Re: Converting a textfile-like string to an array and back: msg#00007

Subject: Re: Converting a textfile-like string to an array and back
* John Douglas Porter <johndporter@xxxxxxxxx> [2003-02-07 14:50]:
> Yes, but his example data was text in a here document.

Then add a note about the caveat.

>   split m,$/, $x, -1;

In bizarre cases, $/ might contain regex metacharacters.
Don't forget the \Q.

> > And popping the last field is dangerous - you don't know if
> > the file ends with a newline.
> 
> You DO know it does, if the text came from a here document.

Once again; dito note caveat.

> Well, I didn't address this part of the problem, but others
> have, giving
> 
>   join $/, @lines, '';
> 
> which is sufficient.  If you're paranoid, you can do

Not if the last line did not end with a record separator.
His example data did, but other data might not.

>   join "\n", @lines, $tail;

Unfortunately, that won't work either - regardless of the
value of $tail - even undef -, you are joining an extra
element onto the string.

If you really don't want that last potentially empty
element, you'll have to do something like:

my $final_recsep = $lines[-1] eq '';
pop @lines if $final_recsep;

# ...

join $/, @lines, $final_recsep ? '' : ();

-- 
Regards,
Aristotle



Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
db.firebase.por...    text.xml.xalan....    qnx.openqnx.dev...    user-groups.zar...    internationaliz...    kde.devel.konve...    finance.e-gold....    emacs.latex.pre...    gis.therion/200...    web.webmin.gene...    yellowdog.gener...    vserver/2003-08...    redhat.release....    sysutils.tivoli...    xfree86.expert/...    mail.becky.user...    hardware.netapp...    netbsd.ports.xe...    python.distutil...    boot-loaders.gr...    culture.interne...    java.springfram...    activedir/2006-...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe