[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] GUSI and mime converting



>Still dawdling with my first program (the mime one) Below is the main part of
>my program (less the actual subroutines). When I asked how to make a popup
>window to select a file with I was shown code similer to what's in the unless
>clause. Unfortunately its workings weren't explained and I get an error 
>saying 'types' is only used once, then it quits.

This is one reason why you should use the 'strict' pragma in all your 
code.  You could also remove the -w flag and things would run, but 
'strict' forces you to declare your variables, which solves the problem 
with "only used once" warnings for good.  With 'strict' you'll need to 
declare all our variables, including those used in subroutines (can be 
done using my()).  Alternatively, you could simply declare the variables, 
without invoking 'strict,' but strict also has other effects you may find 
useful.

Your code, modified ever so slightly:

#!perl -w

use strict;
require "GUSI.ph";
use vars qw(
    $prompt $default
    $file @types $type
    $creator );

unless (@ARGV) {
     $prompt = "Select a file...";
     $default = "Wild Colonials:Desktop Folder:";
     $file = MacPerl::Choose(&GUSI::AF_FILE, 0, $prompt,
          &GUSI::pack_sa_constr_file(@types),
          ($default ? &GUSI::CHOOSE_DEFAULT : 0),$default);
}

foreach $file (@ARGV) {
     print "\n","###############\n", $file, "\n";
     print join "/", reverse MacPerl::GetFileInfo(@ARGV);
     print "\n###############\n";

     BEGINNING:
     $type = MacPerl::Ask('Type?');
     if ($type eq 'die') {die "\n####################\n"}
     if ($type eq 'list') {
          mime_list();
          goto BEGINNING;
     }
     if ($type eq 'list all') {
          mime_list_all();
          goto BEGINNING;
     }
     mime_print();

     $creator = MacPerl::Ask($type.'/Creator?');
     MacPerl::SetFileInfo($creator, $type, $file);
     print "\n####################\n";
}


# Fungal Parataxonomy                   Mycology Information (Mycoinfo)
# Webmaster, Staff Writer      **The World's First Mycology E-Journal**   
# <mailto:webmaster@mycoinfo.com>            <http://www.mycoinfo.com/> 
#
# First they ignore you. Then they laugh at you. Then they fight you.
# Then you win.                                     --Mohandas Gandhi


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org