Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: Drop middle part in a substitution

by !1 (Hermit)
on Jan 26, 2004 at 18:16 UTC ( #324210=note: print w/replies, xml ) Need Help??


in reply to Re: Drop middle part in a substitution
in thread Drop middle part in a substitution

Not to be picky but you are aware that newlines are valid in filenames under some OS's, right?

s/^(\.*\.).*(...)$/$1$2/s;

Of course, two periods within a filename may also throw this off.

Update: Ok. You all got me. I'm a dipshit. Thanks.

Replies are listed 'Best First'.
Re: Re: Re: Drop middle part in a substitution
by Not_a_Number (Prior) on Jan 26, 2004 at 19:56 UTC
    s/^(\.*\.).*(...)$/$1$2/s;

    This doesn't work for me:

    $_ = 'filename.12345Gif'; s/^(\.*\.).*(...)$/$1$2/s; print;

    Output:

    filename.12345Gif

    Drop that first backslash :)

    s/^(.*\.).*(...)$/$1$2/s;

    dave

Re^3: Drop middle part in a substitution
by Roy Johnson (Monsignor) on Jan 26, 2004 at 18:29 UTC
    Two periods should not throw it off: the characters to be discarded were guaranteed not to include any periods, so the greedy match is appropriate.

    As for newlines in filenames: I definitely didn't think of that.


    The PerlMonk tr/// Advocate
Re: Re: Re: Drop middle part in a substitution
by ambrus (Abbot) on Jan 27, 2004 at 15:18 UTC

    AFAIK msdos fat is the only filesystem with 8.3 filenames. But fat does not allow a newline (in fact it allows only very few characters, and definitly no control characters but \x7f.)

Re: Re: Re: Drop middle part in a substitution
by ysth (Canon) on Jan 26, 2004 at 23:49 UTC
    Not to be picky but you are aware that newlines are valid in filenames under some OS's, right? :)

    If the filename ends with a newline, you'll end up keeping the last 4 characters instead of the last three. Try:

    s/^(.*\.).*(...)\z/$1$2/s;
    instead.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://324210]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2021-09-17 04:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?