in reply to how do i do this?

yay, i just learned $, from stepf and runrig. i had done it like this:
use strict; my @sorted_args = sort @ARGV; print "@sorted_args" . "\n";
which could be nice if you need to use the sorted list more than once in the program.

update:
thanks blake for the additional examples and warnings about using $, . sorry if i was unclear above -- i meant that i was posting the way i had done it prior to learning about $,

--cricket
i am smaller than a grasshopper

Replies are listed 'Best First'.
Re: Re: how do i do this?
by blakem (Monsignor) on Sep 30, 2001 at 10:15 UTC
    You mentioned $, but then never used it in your code... In fact, the print statement you have wouldn't be affected by $, anyway. $, is what print displays between its parameters: print $a, $b will actually print $a followed by $, followed by $b.

    The special variable for array interpolation is $". It is what you would need to set to change what happens in your print statement.

    However, anytime you hear "special variable" you need to realize that they are global, and you should avoid changing their global value. This can be done by localized them inside of an enclosing block. If you don't do this, you will introduce hard-to-track-down bugs in other parts of your program. Here is an example using the tips above....

    #!/usr/bin/perl -wT use strict; { local $, = ', '; my @sorted_args = sort @ARGV; print @sorted_args; } print "\nBack to normal: ", @ARGV, "\n"; { local $" = '-'; my @sorted_args = sort @ARGV; print "@sorted_args"; } print "\nBack to normal: @ARGV\n"; =OUTPUT % ./sortedargs.pl c a b a, b, c Back to normal: cab a-b-c Back to normal: c a b

    -Blake