[H-GEN] couple of small perl questions

Byron Ellacott bje at apnic.net
Thu Jan 16 20:34:31 EST 2003


[ Humbug *General* list - semi-serious discussions about Humbug and     ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]

On Fri, 2003-01-17 at 07:34, Tony Nugent wrote:
> I have a text file that I'm reading in, it is created by a windows
> program so it has CR-LF terminated lines.  The chomp and chop
> functions don't seem to work to get rid of them... do I have to
> resort to specifically removing them from the end of each line with
> a regexp deletion of the \015\012 characters?  (In other words, I'd
> like a perl snippit that basically does an on-the-fly dos2unix
> conversion).

$line =~ s/\r\n/\r/;  # should do it

> Also, I'd like to get the called name of the actual script from
> within the program... unlike shell scripts (using $0 to refer to its
> called name), ARGV[0] refers to the first command line arguement.
> The script I'm writing will be "multi-functional" in that it will be
> hard-linked with several different names, and I want it to act
> differently depending on its called name.  And can the same thing be
> done with modules, is it possible for an external module (or even a
> perl function) to identify its own called name?

$0 (that's a zero) or if you're using English, $PROGRAM_NAME.  From the
perlvar man page.

-- 
Byron Ellacott <bje at apnic.net>
APNIC

--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.  See http://www.humbug.org.au/



More information about the General mailing list