anek77713 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Using keys from hashes
by ww (Archbishop) on Jul 17, 2013 at 15:05 UTC

      I guess the answer to this "Can I use..." question is "No". Otherwise he wouldn't need to ask, would he?


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: Using keys from hashes
by davido (Cardinal) on Jul 17, 2013 at 17:10 UTC

    You cannot assign a new value to an existing key. Individual keys are immutable. They can be deleted or added, but not altered. The value they index, of course, may be altered.

    Keys are indices. Think of an array; you cannot interpolate the index of an array into anything. Well, hashes use keys as their index, and there's no syntax for interpolating an index into a quotish construct. At best, you can use a wonky-work-around like this:

    my %hash = ( one_key => 'value', two_key => 'value' ); my $interpolated = "@{[keys %hash]}"; my $interpolated_re = qr/@{[keys %hash]}/; print "Interpolated string: >>>$interpolated<<<\n"; print "Interpolated regexp: >>>$interpolated_re<<<\n";

    Probably a better idea would be to present the problem you're trying to solve along with a minimal but working example of code you've tried, and then ask us how we might go about solving it.


    Dave

      Thnx Dave!!! now I understand)
Re: Using keys from hashes
by Laurent_R (Canon) on Jul 17, 2013 at 18:54 UTC

    Anek, I think that your question is not clear enough, so that the answers you've got so far may or may not be to the point. Please explain a bit more what you are really trying to do.

      my $Bpod = 'B<(.*?)>'; my $B = '<b>'; my $b = '</b>'; my $Ipod = 'I<(.*?)>'; my $I = '<i>'; my $i = '</i>'; my $Upod = 'U<(.*?)>'; my $U = '<u>'; my $u = '</u>'; open(DATA, "<file.pod"); my @file = <DATA>; s/$Bpod/$B$1$b/gi for @file; s/$Ipod/$I$1$i/gi for @file; s/$Upod/$U$1$u/gi for @file;
      I have something like this... to convert POD to HTML and I was thinking how to write this in a better way ...
        See links referenced here, that's how you go about creating a simple parser