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 8591517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:32:46+00:00 2026-06-11T23:32:46+00:00

I’m having trouble with data being exchanged between Perl and Ruby via YAML. I

  • 0

I’m having trouble with data being exchanged between Perl and Ruby via YAML. I have some values that look like number:number, such as 1:16.

Perl’s YAML libraries (Tiny and XS) encode this as 1:16 without quotes. Ruby’s YAML library (Psych) does not interpret this as a string, but instead somehow becomes the Fixnum value 4560. I can’t figure out how to fix this conversion issue on either side.

Every value in the YAML for my use case should be an object or string. So, I could tell the Perl YAML library to quote all values, if such an option existed. Or is there any way to tell the Ruby YAML library to interpret all values as strings? Any ideas?

Changing the language on either side is not logistically an option.

Perl:

use YAML::XS qw(DumpFile);
my $foo={'abc'=>'1:16'};
DumpFile('test.yaml',$foo);

Ruby:

require('yaml')
foo=YAML.load_file('test.yaml')
puts(foo['abc'])

The Ruby code will print 4560. One of the comments figured out how you get 4560 from 1:16, it’s 1 hour, 16 minutes converted to seconds. Uh, okay.

  • 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-06-11T23:32:47+00:00Added an answer on June 11, 2026 at 11:32 pm

    According to the Yaml 1.1 spec, 1:16 is an integer in sexagesimal (base 60) format.

    See also http://yaml.org/type/int.html, which says:

    Using “:” allows expressing integers in base 60, which is convenient for time and angle values.

    The Yaml parser included in Ruby, Psych, recognises this format and converts the value into an integer (wrongly, 1:16 shoud be 71 – the Psych code seems to asume that all such values will be in the form a:b:c but the regex doesn’t enforce that). The Perl emitter (at least YAML::XS which I tested) doesn’t recognise this format, so doesn’t quote the string when writing the file. YAML::XS does recognise and quote some integers, but not all. YAML::XS also doesn’t recognise many other formats (e.g. dates) that Psych does.

    (It appears that the sexagesimal format has been removed from the Yaml 1.2 spec.)

    Psych allows quite a deal of flexibility in its parsing – YAML.load_file is just a simple interface for the common use cases.

    You could use the parse methods of Psych to create a tree representation of the yaml, then convert this into a Ruby data structure using a custom ScalarScanner (which is the object that converts strings of certain formats to the appropriate Ruby type):

    require('yaml')
    
    class MyScalarScanner < Psych::ScalarScanner
      def tokenize string
        #this is the same regexp as Psych uses to detect base 60 ints:
        return string if string =~ /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+$/
        super
      end
    end
    
    tree = YAML::parse_file 'test.yaml'
    foo = Psych::Visitors::ToRuby.new(MyScalarScanner.new).accept tree
    

    This is basically the same process that occurs when you use YAML.load_file, except that it uses the customised scanner class.

    A similar alternative would be to open up ScalarScanner and replace the tokenize method with the customised one. This would allow you to use the simpler load_file interface, but with the usual caveats about monkey patching classes:

    class Psych::ScalarScanner
      alias :orig_tokenize :tokenize
      def tokenize string
        return string if string =~ /^[-+]?[0-9][0-9_]*(:[0-5]?[0-9])+$/
        orig_tokenize string
      end
    end
    
    foo = YAML.load_file 'test.yaml'
    

    Note that these examples only take into consideration values with a format like 1:16. Depending on what your Perl program is emitting you may need to override other patterns too. One in particular that you might want to look at is sexagesimal floats (e.g. 1:16.44).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

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.