Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://336299]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2017-12-14 21:55 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (413 votes). Check out past polls.