[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

meta variable substitution

Felipe Contreras

10/10/2007 2:46:00 PM

Hi,

I'm creating a meta script that can generate both a shell script and a
Makefile. I want the script to be human readable, so I don't want to
substitute all the variables, so $(top_srcdir) =
"/my/obsenely/huge/directory/name" doesn't get substituted in for
example $(srcdir) = $(top_srcdir)/foo.

The problem is that bash doesn't use the same syntax for variable substitution.

I guess the easiest thing to do is just s/$()/${}/ but I was wondering
if there's a better way to do that.

Since I know Rubyists can always find better ways to write code I
decided to ask here.

Is there a better way to implement meta variable substitution?

Best regards.

--
Felipe Contreras

3 Answers

Robert Dober

10/10/2007 3:01:00 PM

0

On 10/10/07, Felipe Contreras <felipe.contreras@gmail.com> wrote:
> Hi,
>
> I'm creating a meta script that can generate both a shell script and a
> Makefile. I want the script to be human readable, so I don't want to
> substitute all the variables, so $(top_srcdir) =
> "/my/obsenely/huge/directory/name" doesn't get substituted in for
> example $(srcdir) = $(top_srcdir)/foo.
>
> The problem is that bash doesn't use the same syntax for variable substitution.
>
> I guess the easiest thing to do is just s/$()/${}/ but I was wondering
> if there's a better way to do that.
>
> Since I know Rubyists can always find better ways to write code I
> decided to ask here.
>
> Is there a better way to implement meta variable substitution?
>
Are you parsing the files? I had the impression that you are
generating them. In that case I would just generate the variable names
rather late and somehow factorize
the code into

def var_name name
"${#{name}}"
end

def var_name name
"$(#{name})"
end

if this polymorphic approach is not suitable for your design an if
statement shall do.

HTH
Robert
--
what do I think about Ruby?
http://ruby-smalltalk.blo...

Felipe Contreras

10/10/2007 3:14:00 PM

0

On 10/10/07, Robert Dober <robert.dober@gmail.com> wrote:
> On 10/10/07, Felipe Contreras <felipe.contreras@gmail.com> wrote:
> > Hi,
> >
> > I'm creating a meta script that can generate both a shell script and a
> > Makefile. I want the script to be human readable, so I don't want to
> > substitute all the variables, so $(top_srcdir) =
> > "/my/obsenely/huge/directory/name" doesn't get substituted in for
> > example $(srcdir) = $(top_srcdir)/foo.
> >
> > The problem is that bash doesn't use the same syntax for variable substitution.
> >
> > I guess the easiest thing to do is just s/$()/${}/ but I was wondering
> > if there's a better way to do that.
> >
> > Since I know Rubyists can always find better ways to write code I
> > decided to ask here.
> >
> > Is there a better way to implement meta variable substitution?
> >
> Are you parsing the files? I had the impression that you are
> generating them. In that case I would just generate the variable names
> rather late and somehow factorize
> the code into

Yeah, I'm generating them.

> def var_name name
> "${#{name}}"
> end
>
> def var_name name
> "$(#{name})"
> end
>
> if this polymorphic approach is not suitable for your design an if
> statement shall do.

A polymorphic approach is fine, but I want this in my code:

foo="<var_start>var_name<var_end>/bar"

So you are suggesting something like:

foo="#{pseudo_var_name}/bar"

Right?

--
Felipe Contreras

mortee

10/10/2007 5:27:00 PM

0