Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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]
[LanX]: such much?
[LanX]: We are speaking nothing but english now...
erix never really understood the need for rhyming slang
[erix]: it seems so far-fateched and illogical
[erix]: islanders a deviant bunch

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2017-03-24 18:26 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (305 votes). Check out past polls.