Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6086247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:43:49+00:00 2026-05-23T11:43:49+00:00

I have a Perl script that creates files, and I want to write into

  • 0

I have a Perl script that creates files, and I want to write into their resource forks, in order to specify the default application they should be opened with (I can’t just change it using get information in Finder, it keeps reverting).

I could find out about Apple’s arcane resource fork stuff, but for my purposes I’m happy to read the data from an existing resource fork that opens with the right application, and hard-code it into my script. The trouble is, I’m too new to Perl to know how to read the hex numbers from the file, copy and paste it into my script, and have it written correctly as hex into my new .rsrc files.

I want to do something like:

my $theHex="DEADBEEF" #<---this is where I would paste the hex from the existing rsrc file
open (OUT, ">$filename/rsrc"); #<--this is the resource fork for file $filename
printf OUT "%x" $theHex #<----I'm not sure that this formatting is right

Edit: Yes I know, resource forks are deprecated. Please tell that to Apple so they can stop using them in their OS to determine things like what application opens a particular file. Sheesh!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:43:49+00:00Added an answer on May 23, 2026 at 11:43 am

    You have a couple problems in that code. First of all, you need a comma after your format string:

    printf OUT "%x", $theHex
    

    Now that we have some syntactically valid source code, we can move on to your real problem. The %x format string for printf expects to be given an integer but you’re giving it a non-numeric string. When the string value of $theHex is converted to an integer, you’ll get zero. The fix for this is easy, you just need to properly initialize $theHex:

    my $theHex = 0xDEADBEEF;
    

    The “0x” prefix tells Perl that you’re writing the number as hex; similarly, a zero prefix (e.g. 0666) indicates octal.

    Now you have a hexadecimal string representation of your 0xDEADBEEF integer.

    If you just want to copy four bytes from one resource fork to another, then you’re better off using read to read four raw bytes and then use print to write those bytes to the other resource fork.

    You might want to have a look at pack if you’re slinging bags’o’bytes around. AFAIK, the resource fork wants four bytes rather than an eight byte human readable hexadecimal representation of a four byte integer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Perl script that I'm attempting to set up using Perl Threads
I have a Perl script that sets up variables near the top for directories
I have a Perl script that I'd like to run on Windows, using either
I have a Perl script that pops up a message box when its work
I have a Perl script that crunches a lot of data. There are a
I have a Perl script that uses WWW::Mechanize to read from a file and
I have a Perl script that takes text values from a MySQL table and
I have a Perl script that launches 2 threads,one for each processor. I need
I have a Perl script that requires a couple of plugins, for istance nmap.
I have a Perl script that will execute three applications. All of it have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.