Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 ( [id://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');

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-03-29 11:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found