Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Can't use string ("STRING") as a HASH ref - Help!

by The Mad Hatter (Priest)
on Mar 12, 2004 at 23:14 UTC ( #336299=note: print w/ replies, xml ) Need Help??


in reply to Can't use string ("STRING") as a HASH ref - Help!

Is the argument you're passing to foo a hash ref? That is, is it what CSS::Style::selectors() expects?

CSS::Style::selectors probably expects to be called like a method (so something like CSS::Style->selectors(shift) instead). You might need to create a CSS::Style object first and then call the method selectors on that with the appropriate argument. Update: You probably shouldn't be using CSS::Style directly in the first place; it appears that all of this should be done via CSS.pm.

In any case, read the doc and verify that $_[0] (what shift gets the value from) really contains what you want.

Update2: Since you said you're new to Perl, here's probably what you want... I've tried to comment it well enough... read the doc and then ask if you need clarification... (Not tested, BTW, all from what the doc says.)

sub foo { my ($file, $selector_name) = @_; # Create CSS object use CSS; my $css = CSS->new; # Read CSS from file passed as first arg to foo $css->read_file($file); # Get CSS::Style object associated with the name of the # selector passed as the second arg to foo my $style = $css->get_style_by_selector($selector_name); # Get selectors (serialized) my $selectors = $style->selectors; # ... } # Example call (as I have foo, it returns nothing, you # can fill that in) my $ret = foo('styles.css', 'body');


Comment on Re: Can't use string ("STRING") as a HASH ref - Help!
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://336299]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2014-09-20 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (159 votes), past polls