Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / August 2005



Tip: Looking for answers? Try searching our database.

Get/set file type/creator in plain Perl?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Iyanaga Nobumi - 02 Aug 2005 07:32 GMT
Hello,

Is it possible to get and/or set the file type and/or creator in  
plain Perl, on OS 10.4.x, without using /Developer/Tools/GetFileInfo  
or /Developer/Tools/SetFile?

Thank you in advance for any idea.

Best regards,

Nobumi Iyanaga
Tokyo,
Japan
emoy@apple.com - 02 Aug 2005 08:47 GMT
> Hello,
>
[quoted text clipped - 9 lines]
> Tokyo,
> Japan

See:

    % perldoc Mac::Files

You should be able to use FSpGetFInfo and FSpSetFInfo.
------------------------------------------------------------------------
--
Edward Moy
Apple

(This message is from me as a reader of this list, and not a statement
from Apple.)
Iyanaga Nobumi - 03 Aug 2005 04:28 GMT
Hello Edward,

>> Hello,
>>
[quoted text clipped - 15 lines]
>
> You should be able to use FSpGetFInfo and FSpSetFInfo.

Thank you for your prompt reply.  I just installed Mac::Carbon, and I  
could get what I wanted with:

use MacPerl;
@res = MacPerl::GetFileInfo("/Users/[me]/Desktop/my_file");
print join ("\n", @res);
    -- NISI
       TEXT

-- In fact, I tried also:

use Mac::Carbon qw(:files);
print FSpGetFInfo "/Users/[me]/Desktop/my_file";

but I got "FInfo=SCALAR(0x1801434)", what I could not understand or  
use...

Anyway, this is what I was looking for.

Now, I would like to use this Perl module from within an AppleScript  
Studio application.  My app would call a Perl script included in its  
Resources folder, and this Perl script would call  
MacPerl::GetFileInfo.  My questions are now:

1.  Is it legal to include the module MacPerl in my application? (I  
would add the credit in my ReadMe)
2.  Will it work (I mean, on users machines, on which Mac::Carbon may  
not be installed), if I include it in the following way?

my_app    -    Contents    - Info.plist
                           - MacOS
                           - PkgInfo
                           - Resources    - English.lproj    - ...
                                          - Scripts          - ...
                                          - myPerlScript.pl
                                          - MacPerl.pm
                                          - auto             -  
MacPerl    - MacPerl.bs
                                                                       
   - MacPerl.bundle

Thank you for your help!

Best regards,

Nobumi Iyanaga
Tokyo,
Japan
Sherm Pendley - 03 Aug 2005 05:02 GMT
> 1.  Is it legal to include the module MacPerl in my application? (I  
> would add the credit in my ReadMe)

You said you're using Tiger. Why not simply use the copy of  
Mac::Carbon that's already pre-installed with the OS?

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Iyanaga Nobumi - 03 Aug 2005 07:12 GMT
Hello Sherm,

>> 1.  Is it legal to include the module MacPerl in my application?  
>> (I would add the credit in my ReadMe)
>
> You said you're using Tiger. Why not simply use the copy of  
> Mac::Carbon that's already pre-installed with the OS?

Well, I couldn't find it on my pre-installed system...  Are you sure  
that it is on it?

Thank you.

Best regards,

Nobumi Iyanaga
Tokyo,
Japan
Sherm Pendley - 03 Aug 2005 14:27 GMT
>> You said you're using Tiger. Why not simply use the copy of  
>> Mac::Carbon that's already pre-installed with the OS?
>
> Well, I couldn't find it on my pre-installed system...  Are you  
> sure that it is on it?

Of course I'm sure.

Finding a file whose name you know is easy - just use the "locate"  
tool at a shell prompt:

    Sherm-Pendleys-Computer:~ sherm$ locate Carbon.pm
    /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level/Mac/
Carbon.pm

The fact that it's in /System/Library/Perl, as opposed to /Library/
Perl, *should* be enough to tell you it came from Apple. But if you  
still have doubts, just use lsbom & grep to check the installer  
package receipts:

    Sherm-Pendleys-Computer:~ sherm$ lsbom /Library/Receipts/
Essentials.pkg/Contents/Archive.bom | grep Carbon.pm
    ./System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level/
Mac/Carbon.pm     100644  0/0     10153      121554408

As you can see, it's in the "Essentials" sub-package of the OS  
install. So, you can count on your users having it - that package is  
not optional.

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Iyanaga Nobumi - 03 Aug 2005 15:35 GMT
Hello Sherm,

Thank you for your reply.

> Finding a file whose name you know is easy - just use the "locate"  
> tool at a shell prompt:
[quoted text clipped - 16 lines]
> install. So, you can count on your users having it - that package  
> is not optional.

Now, I am convinced!  Thank you very much!  I was silly to install  
again Mac::Carbon, but the version I installed (v. 0.74) is probably  
later than the pre-installed version.

But now I have it twice, once in /System/Library/Perl/Extras/5.8.6/
darwin-thread-multi-2level/, and the other in /Library/Perl/5.8.6/
darwin-thread-multi-2level.  Does this make some conflict?  Should I  
delete one of them -- and if so, how would I be able to do that?

Thank you again.

Best regards,

Nobumi Iyanaga
Tokyo,
Japan
Lola Lee - 03 Aug 2005 15:49 GMT
and the other in /Library/Perl/5.8.6/
> darwin-thread-multi-2level.  Does this make some conflict?  Should I  
> delete one of them -- and if so, how would I be able to do that?

Delete this one.  This one should be under your user directory.  The
other one is part of the system and not to be messed around with.

Signature

Lola - mailto:lola@his.com
http://www.lolajl.net | Blog at http://www.lolajl.net/blog/
Terrorismus delendus est! (Terrorism must be destroyed utterly!)
I'm in Bowie, MD, USA, halfway between DC and Annapolis.

Sherm Pendley - 03 Aug 2005 16:22 GMT
> But now I have it twice, once in /System/Library/Perl/Extras/5.8.6/
> darwin-thread-multi-2level/, and the other in /Library/Perl/5.8.6/
> darwin-thread-multi-2level.  Does this make some conflict?

No conflict. @INC is searched in order, and the first one found is  
used. /Library/Perl appears before /System/Library/Perl in @INC for  
precisely this reason, so that you can install newer versions of the  
modules that came with Perl, and they'll be used instead of the older  
ones.

> Should I delete one of them -- and if so, how would I be able to do  
> that?

The redundancy doesn't bother Perl, but if it bothers *you* there's  
no harm in deleting one of them. There's no special magic involved -  
i.e. perl doesn't keep a secret hidden list of all the installed  
modules or anything like that. Just delete the relevant files.

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Ken Williams - 03 Aug 2005 19:08 GMT
>> But now I have it twice, once in
>> /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level/, and
[quoted text clipped - 6 lines]
> modules that came with Perl, and they'll be used instead of the older
> ones.

Unfortunately that's not true, unless it's changed recently:

% perl -le 'print for @INC'
/System/Library/Perl/5.8.1/darwin-thread-multi-2level
/System/Library/Perl/5.8.1
/Library/Perl/5.8.1/darwin-thread-multi-2level
/Library/Perl/5.8.1
/Library/Perl
/Network/Library/Perl/5.8.1/darwin-thread-multi-2level
/Network/Library/Perl/5.8.1
/Network/Library/Perl
.

So if you want to install a copy in /Library/Perl/ and use it rather
than the built-in one, you have to delete the copy in
/System/Library/Perl/ .

 -Ken
Sherm Pendley - 03 Aug 2005 19:36 GMT
>> No conflict. @INC is searched in order, and the first one found is  
>> used. /Library/Perl appears before /System/Library/Perl in @INC  
>> for precisely this reason

> Unfortunately that's not true, unless it's changed recently:

Sorry - I meant to say "/System/Library/Perl/Extras":

    Sherm-Pendleys-Computer:~ sherm$ perl -e 'print join("\n",  
@INC), "\n"'
    /System/Library/Perl/5.8.6/darwin-thread-multi-2level
    /System/Library/Perl/5.8.6
    /Library/Perl/5.8.6/darwin-thread-multi-2level
    /Library/Perl/5.8.6
    /Library/Perl
    /Network/Library/Perl/5.8.6/darwin-thread-multi-2level
    /Network/Library/Perl/5.8.6
    /Network/Library/Perl
    /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level
    /System/Library/Perl/Extras/5.8.6
    /Library/Perl/5.8.1/darwin-thread-multi-2level
    /Library/Perl/5.8.1

And yes, the "Extras" directory *is* a recent addition - it's new to  
Tiger.

> So if you want to install a copy in /Library/Perl/ and use it  
> rather than the built-in one, you have to delete the copy in /
> System/Library/Perl/ .

The easiest thing to do is to let CPAN handle it. It asks when you  
configure it, if you want to use the UNINST option when installing  
modules. That's what that option does - it automagically removes  
older versions of a module, if they would hide the one you're  
installing.

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Lola Lee - 03 Aug 2005 19:41 GMT
> The easiest thing to do is to let CPAN handle it. It asks when you  
> configure it, if you want to use the UNINST option when installing  
> modules. That's what that option does - it automagically removes  older

Now that's really handy to know . . . I'd wondered if there was such an
option.  How do I go into CPAN and change the configurations?  I want to
make sure that is enabled.

Signature

Lola - mailto:lola@his.com
http://www.lolajl.net | Blog at http://www.lolajl.net/blog/
Terrorismus delendus est! (Terrorism must be destroyed utterly!)
I'm in Bowie, MD, USA, halfway between DC and Annapolis.

Sherm Pendley - 03 Aug 2005 20:36 GMT
>> The easiest thing to do is to let CPAN handle it. It asks when  
>> you  configure it, if you want to use the UNINST option when  
[quoted text clipped - 4 lines]
> such an option.  How do I go into CPAN and change the  
> configurations?  I want to make sure that is enabled.

It's an option you pass to "make install" - i.e. "make install  
UNINST=1". Those are defined in the CPAN shell's "make_install_arg"  
config variable. To read the current value of that:

    cpan> o conf make_install_arg
        make_install_arg   UNINST=1

To set it to a new value for this session:

    cpan> o conf make_install_arg UNINST=0
        make_install_arg   UNINST=0

To save any config changes you've made permanently:

    cpan> o conf commit
    commit: wrote /System/Library/Perl/5.8.6/CPAN/Config.pm

To get a list of all the config variables and their values:

    cpan> o conf
    CPAN::Config options from /System/Library/Perl/5.8.6/CPAN/
Config.pm:
    (...SNIP...)

To re-run CPAN's initial setup Q&A:
    cpan> o conf init

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
Iyanaga Nobumi - 04 Aug 2005 15:43 GMT
Hello Sherm and others,

Thank you for all these instructions.  I learned a lot of things.

Best regards,

Nobumi Iyanaga
Tokyo,
Japan

[snip]
> It's an option you pass to "make install" - i.e. "make install  
> UNINST=1". Those are defined in the CPAN shell's "make_install_arg"  
[quoted text clipped - 27 lines]
> Cocoa programming in Perl: http://camelbones.sourceforge.net
> Hire me! My resume: http://www.dot-app.org
John Delacour - 03 Aug 2005 10:02 GMT
>I tried also:
>
>use Mac::Carbon qw(:files);
>print FSpGetFInfo "/Users/[me]/Desktop/my_file";
>
>but I got "FInfo=SCALAR(0x1801434)", what I could not understand or use...

That is because the result is a reference.  You need to dereference
it like this:

#!/usr/bin/perl
use Mac::Carbon qw(:files);
$info_ref =  FSpGetFInfo "$ENV{HOME}/Desktop/ds.jpg";
print  $$info_ref;
## >> JPEG8BIM

See perldoc perlref

JD
Iyanaga Nobumi - 03 Aug 2005 15:36 GMT
Hello John,

>> I tried also:
>>
[quoted text clipped - 13 lines]
> ## >> JPEG8BIM
> See perldoc perlref

Thank you!  I have to learn a lot of things...!  But this is good to  
know.

Best regards,

Nobumi Iyanaga
Tokyo,
Japan
Chris Nandor - 03 Aug 2005 23:48 GMT
The best thing to do for FInfo is *not* to dereference is, but to call the
supplied methods.

`man Mac::Files` and look for FInfo, and see:

      FInfo
          Information for a file, including:

              OSType     fdType            the type of the file
              OSType     fdCreator         file's creator
              U16        fdFlags           flags ex. hasbundle,invisible,
                                           locked, etc.
              Point      fdLocation        file's location in folder

Best to use $info_ref->fdType and $info_ref->fdCreator.  The resulting
scalar on derference, "JPEG8BIM", is not really what it appears, as it has
packed bits for fdFlags and fdLocation, and is length 16, not 8.

OK, yes, it is a bit odd to use a SCALAR ref for that, but you should be
using the methods so you don't need to care.  :-)

Signature

Chris Nandor                      pudge@pobox.com    http://pudge.net/
Open Source Technology Group       pudge@ostg.com     http://ostg.com/

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.