Sudarshan Raghavan wrote:
>
> Sudarshan Raghavan wrote:
> >
> > ($ref_to eq 'ARRAY') && do {
> > foreach my $arr_elem (@{$_}) {
> > $arr_elem =~ s/^\s+//;
> > $arr_elem =~ s/\s+$//;
> > }
> > last S
<[EMAIL PROTECTED]> wrote:
>
> Can someone hlpe me clean up this trim?
>
> Rule: remove all trailing blanks and newline/LF
>
> Do I need a chomp here somewhere?
>
> sub trim
> { my $z = $_[0];
>
> $z =~ s/^\s+//;
> $z =~ s/\s+$//;
>
> return $z;
> }
Do you mean /leading/ and trailing, which
> On Tue, 14 Oct 2003 19:26:50 -0700, perl wrote:
>> Can someone hlpe me clean up this trim?
>
> What do you actually mean by "clean up"? Make the code shorter and,
> maybe, more obfuscated? Why?
--
- more shorter - Yes
- more obfuscated - hhmm... nice to know shortcut
--
>
>>
On Tue, 14 Oct 2003 19:26:50 -0700, perl wrote:
> Can someone hlpe me clean up this trim?
What do you actually mean by "clean up"? Make the code shorter and,
maybe, more obfuscated? Why?
> Rule: remove all trailing blanks and newline/LF
sub trim {
my $string = shift;
chomp( $str
Sudarshan Raghavan wrote:
> simran wrote:
>
> > I wrote my self this subroutine... which comes in very handy :-)
> >
> > ..snip
> >
> > sub strip {
> > my $self = shift;
> > my $ref = shift;
> >
> > if (! ref($ref)) {
> > $ref =~ s/(^[\s\t]*)|([\s\t]*$)//g if (defined $ref);
>
> Why is
simran wrote:
> I wrote my self this subroutine... which comes in very handy :-)
>
> ..snip
>
> sub strip {
> my $self = shift;
> my $ref = shift;
>
> if (! ref($ref)) {
> $ref =~ s/(^[\s\t]*)|([\s\t]*$)//g if (defined $ref);
Why is it better to do this in two steps? Read through this
I wrote my self this subroutine... which comes in very handy :-)
#
# strip
#
=head2 strip
=over
=item Description
Strips out leading and training whitespaces from references...
=item Input
* Reference to an array, hash or string
or
A string
=item Return
* If input was a refer
[EMAIL PROTECTED] wrote:
> Can someone hlpe me clean up this trim?
>
> Rule: remove all trailing blanks and newline/LF
perldoc -q 'How do I strip blank space from the beginning/end of a
string'
>
>
> Do I need a chomp here somewhere?
No, the \s+ will take care of that
>
>
> sub trim
> { my $
Can someone hlpe me clean up this trim?
Rule: remove all trailing blanks and newline/LF
Do I need a chomp here somewhere?
sub trim
{ my $z = $_[0];
$z =~ s/^\s+//;
$z =~ s/\s+$//;
return $z;
}
thanks,
-rkl
-
eMail solutions by
http://www.swanma