how to heredoc without interpolation and backslash interpretation with arbitrary length delimiter su

A

ashishwave

Hi,
how to do heredoc without interpolation and backslashes interpretation
with arbitrary delimiter support (not just a single character)

let me explain my point:

# here #{var1} gets interpolated
puts <<EOL
hello #{var1}
EOL

#here interpolation is off, backslashes interpretation is off, but
you have to delimit it insingle character {} @@ !! .If your
heredoc string itself is very complex and contains all ASCII
charcaters and combo of backslashes then it becomes unsuable.
puts %Q{
hello #var1
}

SOMETHING LIKE THIS SHOULD BE ADDED TO/POSSIBLE IN RUBY
#HERE NOTHING GETS INTERPOLATED AND backslashes also remain there.
puts %Q{<<EOLLLL
@#$%^%&%&%&%SFSFSV #{abc} #{que} \r\n
\n
EOLLLL
}

Many times i have lots of jumbled up patterns from h/w device
responses or i want to embed binary/image files itself inside ruby
source code, then i am not able to do it with interpolation (which
creates problem for #{ occurence ) or with backslash interpretation
and also if i try to do it with single character delimters like %Q and
{} [] !! @@ combination THEN single character } or ! or @ etc are more
likely to appear in binary string itself ; creating problems for me.
So i need my own relevant custom arbitrary length delimiter (like
EOLLLL here) with this too, which is lot less less likely to appear in
the heredoced string than a single delimited character.

So how to do it?

bye :)
Ashish Ranjan
(e-mail address removed)
 
J

Jano Svitok

Hi,
how to do heredoc without interpolation and backslashes interpretation
with arbitrary delimiter support (not just a single character)

let me explain my point:

# here #{var1} gets interpolated
puts <<EOL
hello #{var1}
EOL

#here interpolation is off, backslashes interpretation is off, but
you have to delimit it insingle character {} @@ !! .If your
heredoc string itself is very complex and contains all ASCII
charcaters and combo of backslashes then it becomes unsuable.
puts %Q{
hello #var1
}

SOMETHING LIKE THIS SHOULD BE ADDED TO/POSSIBLE IN RUBY
#HERE NOTHING GETS INTERPOLATED AND backslashes also remain there.
puts %Q{<<EOLLLL
@#$%^%&%&%&%SFSFSV #{abc} #{que} \r\n
\n
EOLLLL
}

Many times i have lots of jumbled up patterns from h/w device
responses or i want to embed binary/image files itself inside ruby
source code, then i am not able to do it with interpolation (which
creates problem for #{ occurence ) or with backslash interpretation
and also if i try to do it with single character delimters like %Q and
{} [] !! @@ combination THEN single character } or ! or @ etc are more
likely to appear in binary string itself ; creating problems for me.
So i need my own relevant custom arbitrary length delimiter (like
EOLLLL here) with this too, which is lot less less likely to appear in
the heredoced string than a single delimited character.

So how to do it?

http://www.zenspider.com/Languages/Ruby/QuickRef.html#8

Here Docs

<<identifier - interpolated, goes until identifier
<<"identifier" - same thing
<<'identifier' - no interpolation
<<-identifier - you can indent the identifier by using "-" in front
 
S

Stefano Crocco

Alle venerd=EC 17 agosto 2007, ashishwave ha scritto:
Hi,
how to do heredoc without interpolation and backslashes interpretation
with arbitrary delimiter support (not just a single character)

let me explain my point:

# here #{var1} gets interpolated
puts <<EOL
hello #{var1}
EOL

#here interpolation is off, backslashes interpretation is off, but
you have to delimit it insingle character {} @@ !! .If your
heredoc string itself is very complex and contains all ASCII
charcaters and combo of backslashes then it becomes unsuable.
puts %Q{
hello #var1
}

Are you sure? If I remember correctly, %Q works like a double quoted string=
,=20
so interpolation happens and backslashes are still interpreted. I think her=
e=20
you mean %q, instead.
SOMETHING LIKE THIS SHOULD BE ADDED TO/POSSIBLE IN RUBY
#HERE NOTHING GETS INTERPOLATED AND backslashes also remain there.
puts %Q{<<EOLLLL
@#$%^%&%&%&%SFSFSV #{abc} #{que} \r\n
\n
EOLLLL
}

Many times i have lots of jumbled up patterns from h/w device
responses or i want to embed binary/image files itself inside ruby
source code, then i am not able to do it with interpolation (which
creates problem for #{ occurence ) or with backslash interpretation
and also if i try to do it with single character delimters like %Q and
{} [] !! @@ combination THEN single character } or ! or @ etc are more
likely to appear in binary string itself ; creating problems for me.
So i need my own relevant custom arbitrary length delimiter (like
EOLLLL here) with this too, which is lot less less likely to appear in
the heredoced string than a single delimited character.

So how to do it?

bye :)
Ashish Ranjan
(e-mail address removed)

To get 'single quoted' heredoc, you need to single-quote the delimiter stri=
ng:

puts <<'A_VERY_LONG_STRING'
hello #{var1}
A_VERY_LONG_STRING
=3D> hello #{var1}

(note that the delimiter string is only quoted at the beginning of the=20
heredoc, not at the end).

I hope this helps

Stefano
 
A

ashishwave

ya, i actually meant %q (not %Q) i mistyped

anyway, thanks jano, it worked
bye :)
Ashish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top