Ugly style variables

I’m new to ruby, and thus far I mostly like what I’ve seen. But these
$_, $&, and the other, ugly style variables that ruby inherited from
Perl. Let’s say I’m not in love with them. Is there an alternative way
to obtain the same functionality, but in a more verbose and intuitive
way?

Perl. Let's say I'm not in love with them. Is there an alternative way
to obtain the same functionality, but in a more verbose and intuitive
way?

Well, you have lib/English.rb which create aliases, for example

pigeon% head English.rb
alias $ERROR_INFO $!
alias $ERROR_POSITION $@
alias $LOADED_FEATURES $"
alias $FS $;
alias $FIELD_SEPARATOR $;
alias $OFS $,
alias $OUTPUT_FIELD_SEPARATOR $,
alias $RS $/
alias $INPUT_RECORD_SEPARATOR $/
alias $ORS $\
pigeon%

Guy Decoux

Hi,

···

At Wed, 30 Apr 2003 19:34:02 +0900, saggmannen wrote:

I’m new to ruby, and thus far I mostly like what I’ve seen. But these
$_, $&, and the other, ugly style variables that ruby inherited from
Perl. Let’s say I’m not in love with them. Is there an alternative way
to obtain the same functionality, but in a more verbose and intuitive
way?

Of course you can use explicit variables.

while (<>) { while line = gets
next if /^#/; next if /^#/ =~ line
print; print line
} end
$x = $1 if /foo(.)/; x = m[1] if m = /foo(.)/.match(line)


Nobu Nakada

Saluton!

I’m new to ruby, and thus far I mostly like what I’ve seen. But
these $_, $&, and the other, ugly style variables that ruby
inherited from Perl. Let’s say I’m not in love with them. Is there
an alternative way to obtain the same functionality, but in a more
verbose and intuitive way?

require 'English"

is equivalent to:

alias $ERROR_INFO $!
alias $ERROR_POSITION $@
alias $LOADED_FEATURES $"
alias $FS $;
alias $FIELD_SEPARATOR $;
alias $OFS $,
alias $OUTPUT_FIELD_SEPARATOR $,
alias $RS $/
alias $INPUT_RECORD_SEPARATOR $/
alias $ORS $
alias $OUTPUT_RECORD_SEPARATOR $
alias $INPUT_LINE_NUMBER $.
alias $NR $.
alias $LAST_READ_LINE $_
alias $DEFAULT_OUTPUT $>
alias $DEFAULT_INPUT $<
alias $PID $$
alias $PROCESS_ID $$
alias $CHILD_STATUS $?
alias $LAST_MATCH_INFO $~
alias $IGNORECASE $=
alias $PROGRAM_NAME $0
alias $ARGV $*
alias $MATCH $&
alias $PREMATCH $`
alias $POSTMATCH $’
alias $LAST_PAREN_MATCH $+

Gis,

Josef ‘Jupp’ Schugt

···

/“”“”\ e-mails that do not contain plain text, are larger than |
/ STOP \ 50 KiB, are unsolicited, or contain binarys are ignored |
\ SPAM / unless payment from your side or technical reasons give |
____/ rise to a non-standard treatment. ______________________|

and some have aliases already: e.g. $: has one but I can never remember it
(digs through Ruby source code… ah yes, it’s $LOAD_PATH)

Regards,

Brian.

···

On Wed, Apr 30, 2003 at 08:53:01PM +0900, ts wrote:

Perl. Let’s say I’m not in love with them. Is there an alternative way
to obtain the same functionality, but in a more verbose and intuitive
way?

Well, you have lib/English.rb which create aliases, for example

pigeon% head English.rb
alias $ERROR_INFO $!

Actually, I tend to remember $: more easily than $LOAD_PATH. I think it
is a bit ironic that the mnemonic version is harder to remember (at
least for me) :slight_smile:

···

On Wed, 2003-04-30 at 09:09, Brian Candler wrote:

On Wed, Apr 30, 2003 at 08:53:01PM +0900, ts wrote:

Perl. Let’s say I’m not in love with them. Is there an alternative way
to obtain the same functionality, but in a more verbose and intuitive
way?

Well, you have lib/English.rb which create aliases, for example

pigeon% head English.rb
alias $ERROR_INFO $!

and some have aliases already: e.g. $: has one but I can never remember it
(digs through Ruby source code… ah yes, it’s $LOAD_PATH)


– Jim Weirich jweirich@one.net http://w3.one.net/~jweirich

“Beware of bugs in the above code; I have only proved it correct,
not tried it.” – Donald Knuth (in a memo to Peter van Emde Boas)

Happens to me to. It’s because of the underscore, I never remember if
there’s one or not.

···

On Thu, May 01, 2003 at 08:17:39AM +0900, Jim Weirich wrote:

On Wed, 2003-04-30 at 09:09, Brian Candler wrote:

On Wed, Apr 30, 2003 at 08:53:01PM +0900, ts wrote:

Perl. Let’s say I’m not in love with them. Is there an alternative way
to obtain the same functionality, but in a more verbose and intuitive
way?

Well, you have lib/English.rb which create aliases, for example

pigeon% head English.rb
alias $ERROR_INFO $!

and some have aliases already: e.g. $: has one but I can never remember it
(digs through Ruby source code… ah yes, it’s $LOAD_PATH)

Actually, I tend to remember $: more easily than $LOAD_PATH. I think it
is a bit ironic that the mnemonic version is harder to remember (at
least for me) :slight_smile:


_ _

__ __ | | ___ _ __ ___ __ _ _ __
'_ \ / | __/ __| '_ _ \ / ` | ’ \
) | (| | |
__ \ | | | | | (| | | | |
.__/ _,
|_|/| || ||_,|| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

snafu = Situation Normal All F%$*ed up