Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Konversation script

Status
Not open for further replies.

krammer

IS-IT--Management
Jul 15, 2007
59
US
I have made a perl script for the IRC Linux kde client "Konversation." What I want to do it modify this script so it uses a different smiley face depending on the month. So in October the smiley face would be orange, or december it would be green and red. Here is what I have, thanks to anyone who can help...

Code:
#!/usr/bin/env perl

# colored smile script for konversation
# has been tested on debian


$PORT = shift;
$SERVER = shift;
$TARGET = shift;


exec 'dcop', $PORT, 'default', 'say', $SERVER, $TARGET, "%B%C3: %C4)%C%B"
 
Code:
"%B%C3: %C4)%C%B"
You'd playing with these values i'd guess, but what the alternates are I have no idea, would be more of a question for the Linux forums...

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Yeah those are the values to change the colors...but I am talking about using an if/then statement for what month is it, and then have a certain color set for that...this is the right form to ask on since its perl....
 
Look at hashes.
%color ( 'Jan' => ':)', 'Feb' => ':D',);

For example

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Code:
#!/usr/bin/env perl

# colored smile script for konversation
# has been tested on debian


$PORT = shift;
$SERVER = shift;
$TARGET = shift;

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
%color1=('Jan'=>"%B%C3:", 'Feb'=>"%B%C3:", 'Mar'=>"%B%C3:", 
		 'Apr'=>"%B%C3:",'May'=>"%B%C3:",'Jun'=>"%B%C3:",
		 'Jul',=>"%B%C3:",'Aug'=>"%B%C3:"'Sep'=>"%B%C3:",
		 'Oct'=>"%B%C3:",'Nov'=>"%B%C3:",'Dec'=>"%B%C3:";
%color2=('Jan'=>""%C4)%C%B", 'Feb'=>"%C4)%C%B", 'Mar'=>"%C4)%C%B", 
		 'Apr'=>""%C4)%C%B",'May'=>"%C4)%C%B",'Jun'=>"%C4)%C%B",
		 'Jul',=>""%C4)%C%B",'Aug'=>"%C4)%C%B","'Sep'=>"%C4)%C%B",
		 'Oct'=>"%C4)%C%B",'Nov'=>"%C4)%C%B",'Dec'=>"%C4)%C%B";


#  get the picture
exec 'dcop', $PORT, 'default', 'say', $SERVER, $TARGET, $color1{$mon}." ".$color2{$mon}";
Not tested ... and you'll need to sort out your own colors ...

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Am I on the right track here??

Code:
$PORT = shift;
$SERVER = shift;
$TARGET = shift;


%color =    (
    'Jan' => "%B%C3: %C4)%C%B",
    'Feb' => "%B%C3: %C4)%C%B",
    'Mar' => "%B%C3: %C4)%C%B",
    'Apr' => "%B%C3: %C4)%C%B",
    'May' => "%B%C3: %C4)%C%B",
    'Jun' => "%B%C3: %C4)%C%B",
    'Jul' => "%B%C3: %C4)%C%B",
    'Aug' => "%B%C3: %C4)%C%B",
    'Sep' => "%B%C3: %C4)%C%B",
    'Oct' => "%B%C3: %C4)%C%B",
    'Nov' => "%B%C3: %C4)%C%B",
    'Dec' => "%B%C3: %C4)%C%B",
);

foreach $month (keys %color)
    {
    if ($val = $data{$month})
        {
        exec 'dcop', $PORT, 'default', 'say', $SERVER, $TARGET, %color
        }
    }
 
Oh wow thanks Paul, that was literally 10 min before my post when I was writing it...thanks. I'll test it out and let you know.
 
I'm not sure where $val is coming from?

What you probably need is to get the month somehow (localtime()?) and use your hash.

For example
$month = 'Jan';

and then just do

exec 'dcop', $PORT, 'default', 'day', $SERVER, $TARGET, $color{$month};

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
sub datetime {
($sec, $min, $hour, $day, $month, $year) = localtime;
$month++;
$year += 1900;
$_ = sprintf("%02d", $_) for ($sec, $min, $hour, $day, $month);
}


Should help you out to :)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
It doesn't seem to be working paul...I think it has to do with how the last line is written...I also cleaned up some typos with the quotations, so everything before this looks clean now.

Code:
exec 'dcop', $PORT, 'default', 'say', $SERVER, $TARGET, $color1{$mon}." ".$color2{$mon}";
 
exec 'dcop', $PORT, 'default', 'say', $SERVER, $TARGET, $color1{$mon}$color2{$mon};

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
well your going to have to give some more information.. I left the double quotes out earlier on accident..


exec 'dcop', $PORT, 'default', 'say', $SERVER, $TARGET, "$color1{$mon}$color2{$mon}";

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
I don't know what other information I can give you...I run the script and nothing happens...
 
did the exec work before you change it? Print he value of $mon before the exec and see what it says.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
It worked with my first post...when I print $mon, it prints the number of the month, and not "Dec". Does this have something to do with it?
 
Travis,

what is this function supposed to do?

Code:
sub datetime {
    ($sec, $min, $hour, $day, $month, $year) = localtime;
    $month++;
    $year  += 1900;
    $_ = sprintf("%02d", $_) for ($sec, $min, $hour, $day, $month);
}




------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Yup that was it!

Code:
$PORT = shift;
$SERVER = shift;
$TARGET = shift;

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
%color1=('0'=>"%B%C3: ", '1'=>"%B%C4: ", '2'=>"%B%C3: ",
         '3'=>"%B%C3: ",'4'=>"%B%C3: ",'5'=>"%B%C3: ",
         '6',=>"%B%C3: ",'7'=>"%B%C3: ",'8'=>"%B%C11: ",
         '9'=>"%B%C3: ",'10'=>"%B%C11: ",'11'=>"%B%C3: ");
%color2=('0'=>"%C2)%C%B", '1'=>"%C4)%C%B", '2'=>"%C9)%C%B",
         '3'=>"%C8)%C%B",'4'=>"%C12)%C%B",'5'=>"%C11)%C%B",
         '6',=>"%C2)%C%B",'7'=>"%C0)%C%B",'8'=>"%C0)%C%B",
         '9'=>"%C7)%C%B",'10'=>"%C9)%C%B",'11'=>"%C4)%C%B");


exec 'dcop', $PORT, 'default', 'say', $SERVER, $TARGET, "$color1{$mon}$color2{$mon}"
 
Gives him the month in $month .. but he's using $mon so I don't know how he's getting the current month.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Code:
[blue]$PORT[/blue] = [url=http://perldoc.perl.org/functions/shift.html][black][b]shift[/b][/black][/url][red];[/red]
[blue]$SERVER[/blue] = [black][b]shift[/b][/black][red];[/red]
[blue]$TARGET[/blue] = [black][b]shift[/b][/black][red];[/red]


[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]%color[/blue] =    [red]([/red]
    [fuchsia]0[/fuchsia] => [red]"[/red][purple]%B%C3: %C4)%C%B[/purple][red]"[/red],
    [fuchsia]1[/fuchsia] => [red]"[/red][purple]%B%C3: %C4)%C%B[/purple][red]"[/red],
    [fuchsia]2[/fuchsia] => [red]"[/red][purple]%B%C3: %C4)%C%B[/purple][red]"[/red],
    [fuchsia]3[/fuchsia] => [red]"[/red][purple]%B%C3: %C4)%C%B[/purple][red]"[/red],
    [fuchsia]4[/fuchsia] => [red]"[/red][purple]%B%C3: %C4)%C%B[/purple][red]"[/red],
    [fuchsia]5[/fuchsia] => [red]"[/red][purple]%B%C3: %C4)%C%B[/purple][red]"[/red],
    [fuchsia]6[/fuchsia] => [red]"[/red][purple]%B%C3: %C4)%C%B[/purple][red]"[/red],
    [fuchsia]7[/fuchsia] => [red]"[/red][purple]%B%C3: %C4)%C%B[/purple][red]"[/red],
    [fuchsia]8[/fuchsia] => [red]"[/red][purple]%B%C3: %C4)%C%B[/purple][red]"[/red],
    [fuchsia]9[/fuchsia] => [red]"[/red][purple]%B%C3: %C4)%C%B[/purple][red]"[/red],
    [fuchsia]10[/fuchsia] => [red]"[/red][purple]%B%C3: %C4)%C%B[/purple][red]"[/red],
    [fuchsia]11[/fuchsia] => [red]"[/red][purple]%B%C3: %C4)%C%B[/purple][red]"[/red],
[red])[/red][red];[/red]

[url=http://perldoc.perl.org/functions/exec.html][black][b]exec[/b][/black][/url] [red]'[/red][purple]dcop[/purple][red]'[/red], [blue]$PORT[/blue], [red]'[/red][purple]default[/purple][red]'[/red], [red]'[/red][purple]say[/purple][red]'[/red], [blue]$SERVER[/blue], [blue]$TARGET[/blue], [blue]$color[/blue][red]{[/red][red]([/red][url=http://perldoc.perl.org/functions/localtime.html][black][b]localtime[/b][/black][/url][red])[/red][red][[/red][fuchsia]4[/fuchsia][red]][/red][red]}[/red][red];[/red]

0 is January and 11 is December

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top