Subject: FVWM: FvwmPerl problem

From: Shay Hill <[email-masked]>
Date: Mon, 19 Jan 2004 09:25:49 -0600

version 2.5.8

I have written a working perl script to read colors from my .fvwm2rc 
file and build appropriately colored icons. The script *works* from the 
command line, but fails when called from .fvwm2rc. with
FvwmPerl load create-icons.fpl

Here is a minimal version of my perl script. There are some lines 
commented out. The script works, but is of course useless, without these 
lines. With these lines, the output file fails to open when called from 
.fvwm2rc.

#!/usr/bin/perl
open(FVWM, "/home/shay/.fvwm/.fvwm2rc");
undef $/;
$_ = <FVWM>;
close FVWM;
# /SetEnv FGColor "(.*[^"])"\n/g;
# $FGC = $1;
open(OUT, ">/home/shay/.fvwm/iconify.xpm");   
print OUT "\". c $FGC\",\n";
close OUT;

Any help appreciated. I have worked on this a lot and have become very 
frustrated.

 -Shay

--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Scott McWhirter <[email-masked]>
Date: Mon, 19 Jan 2004 19:50:40 +0000

> print OUT "\". c $FGC\",\n";

This doesn't appear to do anything useful what so ever, in fact i'd be
surprised if it ever passed perl syntax check.
  `perl -cw script.pl`

Contact me off-list with information on what you need to achieve and
i'll try to help ye out.

-- 
-Scott McWhirter- | -kungfuftr-

---

From: Mikhael Goikhman <[email-masked]>
Date: Mon, 19 Jan 2004 21:04:16 +0000

> FvwmPerl load create-icons.fpl

The correct syntax is:

  FvwmPerl --load create-icons.fpl

But why do you need FvwmPerl at all here? It seems that your script does
not use any FvwmPerl features and does not send any fvwm commands back,
so you may just do:

  Exec create-icons

Or if you need syncronization, then:

  PipeRead create-icons

> Any help appreciated. I have worked on this a lot and have become very 

Sorry, it is impossible to determine why your script fails. Maybe because
you don't use the correct FvwmPerl syntax (--load). Or maybe because the
files can't be open, or there is some perl error (but then FvwmPerl
should catch it and report on the X standard error file).

You may use some sane programming techniques to make programs more solid
and less buggy. For example, ask Perl to help you with such goal by
starting the script with:

	#!/usr/bin/perl -w
	use strict;

Never write:

	open(...);

If you want to catch problems, write something like:

	open(...) or die "Can't open file $fileName: $!\n";

Never write:

	/..(..)../;
	$color = $1;

$1 will contain random garbage if there is no match. Write something like:

	if (/..(..)../) {
		$color = $1;
	}

or:

	/..(..)../ and $color = $1;

or:

	/..(..)../ || die "Expected string not found";
	$color = $1;

There are several ways to preprocess XPM with symbolic colors to final
XPM. Which one is better depends on your goals and setup. You may just
call a shell/perl script when you start fvwm to create all final XPMs.
Or use one of these to do this:

  ModuleSynchronous FvwmCpp -debug -lock -noread -outfile processed.xpm unprocessed.xpm
  ModuleSynchronous FvwmPerl --preprocess --nosend --noremove unprocessed.xpm

(and not "FvwmPerl --load").

Another solution is to preprocess your whole configuration (and not just
icons) using "FvwmPerl -p .fvwm2rc.ppp" and create the needed icons in
the embeded perl of this .fvwm2rc.ppp file.

Finally, you may write your own fvwm module if you want so and listen to
colorset info from fvwm.

But if you don't want to do a lot of programming, then I think the
easiest solution for you is to prepare the final XPM sets statically and
just use one or another ImagePath depending on your color scheme:

  ImagePath $[FVWM_USERDIR]/images/red-color-scheme:+

Then prepare ~/.fvwm/images/red-color-scheme/iconify.xpm and so on.

Regards,
Mikhael.

---

From: Scott McWhirter <[email-masked]>
Date: Mon, 19 Jan 2004 21:30:37 +0000

On Mon, Jan 19, 2004 at 09:04:16PM +0000, Mikhael Goikhman wrote:
Sorry, i'm going to do a short perl rant...

> 	open(...) or die "Can't open file $fileName: $!\n";
If he doesn't understand the syntax why should he write it? There are
lots of people that say... do it this way... but don't explain why. If
you say to someone, you should do it this way... explain why and what the
syntax means.

For reference,
open(MOO,$file) or die "Barf on $file: $!\n";

If the open fails for some reason (permissions?) it will run the code
after the "or". So in this case it would die and give the message
supplied. $! in perl is a special variable containing any error messages
from external sources (ie: the file open).

blah... hhhmmm... MJD-ish

---

From: Thomas Adam <[email-masked]>
Date: Mon, 19 Jan 2004 22:32:57 +0000 (GMT)

> you say to someone, you should do it this way... explain why and what

Oh, come now! Everyone knows that Perl's motto is: TMTOWTDI. The reason
why he should write it a certain way is because it is the correct way.
Mikhael did actually explain why, but not in so much detail. That is why
the man pages and copious book exist about perl
 
> from external sources (ie: the file open).

Actually $! will contain whatever error message is thrown up at that time.

-- Thomas Adam

=====
"The Linux Weekend Mechanic" -- http://linuxgazette.net
"TAG Editor"                 -- http://linuxgazette.net

"<shrug> We'll just save up your sins, Thomas, and punish 
you for all of them at once when you get better. The 
experience will probably kill you. :)"

 -- Benjamin A. Okopnik (Linux Gazette Technical Editor)

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" 
your friends today! Download Messenger Now 
http://uk.messenger.yahoo.com/download/index.html
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Mikhael Goikhman <[email-masked]>
Date: Tue, 20 Jan 2004 01:05:48 +0000

On 19 Jan 2004 21:30:37 +0000, Scott McWhirter wrote:
> 
> If he doesn't understand the syntax why should he write it?

Your messages in this thread suggest that Shay is pretty much ignorant of
Perl. This seems incorrect, since he wrote an XPM generation script that
worked for him from a shell.

> blah... hhhmmm... MJD-ish

The interesting thing is that I actualy thought about MJD when suggested
"use strict;".  (I happened to meet him.)  So I weighted the wording
carefully.  And, no, I don't always use this pragma myself.  My signature
would fail with it. :-)  At least it passes "use warnings;".

Regards,
Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'

---

From: Shay Hill <[email-masked]>
Date: Tue, 20 Jan 2004 13:25:53 -0600

Thank you both. The script is now working and of course more robust.
 -Shay