Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

%% in perl mean

by shibicbe (Initiate)
on Sep 11, 2013 at 16:26 UTC ( #1053520=perlquestion: print w/ replies, xml ) Need Help??
shibicbe has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

what is the meaning of "%%" in perl

I couldnt get any clue on it

Here's the code

if( QLearn('LEARN') ) { $var->{SPEC} =~ s/%%/$var->{LEARN}{TEST}/ ; }

what is the meaning of the above statement badly in need of help

Thank in advance for the help

Comment on %% in perl mean
Download Code
Re: %% in perl mean
by keszler (Priest) on Sep 11, 2013 at 16:59 UTC
    Binding Operators and Regexp Quote Like Operators

    If the string in $var->{SPEC} contains the characters "%%", the first occurance of "%%" will be changed to whatever string is in the variable $var->{LEARN}{TEST}. (Assuming that if( QLearn('LEARN') ) is true.)

Re: %% in perl mean
by SuicideJunkie (Priest) on Sep 11, 2013 at 17:04 UTC

    That's just some '%' characters to search for. Perhaps what you really want to know is what the s/// part is all about.

Search and replace
by Laurent_R (Vicar) on Sep 11, 2013 at 17:26 UTC

    Just look what it does:

    DB<10> $string = 'foo%%bar'; DB<11> $string =~ s/%%/BAZ/; DB<12> print $string fooBAZbar DB<13>
Re: %% in perl mean
by tobyink (Abbot) on Sep 11, 2013 at 20:34 UTC

    In this case, it's just two percent character which are being searched for in a search-and-replace operation (s///). However it does have two special meanings in Perl...

    1. The printf and sprintf functions take a formatting string as their first argument. This formatting string uses special codes that start with a "%" character; such as "%d" which is a placeholder for an integer. When you want the output to include a literal "%" character, you can't just place that as-is in the formatting string; instead you use "%%".

    2. The other place "%%" is special in Perl is that there's a global hash called %%. You can assign values to it and use it like any other hash; the only difference is that you don't declare it with my or our - it's pre-defined.

      use Data::Dumper; %% = (foo => 1, bar => 2); print Dumper \%%;
    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re: %% in perl mean
by Anonymous Monk on Sep 11, 2013 at 22:25 UTC
Re: %% in perl mean
by Jim (Curate) on Sep 11, 2013 at 22:27 UTC

    This appears to be a snippet from an ad hoc template processing Perl script. Is it? If so, then the pairs of percent symbols (%%) are likely tags in the template that are matched and replaced with variable text; specifically, the value referred to by the hash variable $var->{LEARN}{TEST}.

Re: %% in perl mean
by Anonymous Monk on Sep 11, 2013 at 23:24 UTC
    This is probably just a means-nothing token that is meant to be put into a template-string of some kind to mark the place where (in this very statement) a substitution is to be performed. Look at the content of this element of "$var" and see if, as I suspect, it contains that particular substring at a fortuitous place.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1053520]
Approved by ww
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-08-21 07:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (128 votes), past polls