in reply to Re: Re: Re: No other way?
in thread No other way?

given that the grep for /^$/ was to skip the null first field returned by split (because the first character in the string was the delimiter "/"), wouldn't it be "better" (more readable) to just explicitly remove it- ie
s#^/##; # remove the leading delimiter

The code as written silently munches all null fields which is fine because we don't expect a directory called null (ie in /foo/bar//rab/oof) but if the idiom is transported to another set of data...

split /' '/ nicely removes any leading white space... it could be handy to have an option to do this for other delimiters.

--
my $chainsaw = 'Perl';

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: No other way?
by chip (Curate) on Dec 14, 2001 at 01:40 UTC
    Well, in order to do a substitution you might have to assign to a new variable so as not to modify the original value, and that could be a worse readability hit than the grep; depends on the context.

    PS: I think you meant s#^/+##, what with the possibility of multiple leading slashes.

        -- Chip Salzenberg, Free-Floating Agent of Chaos